Remembering of course that we need to select the “Pass execution context as first parameter” option in the Handler Properties dialogue when defining our event handlers on the form.
When we select Customise Command in Ribbon Workbench we can pass Execution Parameters.
I’ve chosen to modify the Command for this custom Name button:
Now after selecting the Add Parameter, we select CRM Parameter:
And then select Primary Control:
Now you can get formContext from this parameter as easily as if it were the executionContext.
If you are calling this for a button on the Home or SubGrid ribbons, then your code will look like this:
And if you are calling this for a button on the Form ribbon, you can use primaryControl as if it were the formContext: