[Update]: The PrimaryControl CRM parameter passed is formContext which can be used further to get the value of the attribute.
While working on upgrade activities of D365 V9 from D365 V8, we faced one weird issue related to Enable Rule of Ribbon button.
We had one form where we were using Enable Rule for a button which was defined using custom JS code. As part of client side scripting changes related to D365 V9 upgrade, we passed Primary Control as first CRM parameter in Ribbon Workbench for that Enable Rule as explained here and in JS we passed executionContext as a parameter as shown below:
DisplayReadyForPMU: function (executionContext) { debugger; var formContext = executionContext.getFormContext(); var campaignType = formContext.getAttribute("sab_outputtype").getValue(); ... }
While testing after making the above changes, we got the error “Cannot read property ‘getFormContext’ of undefined”

While debugging the code using Developer Tools in browser, we found that executionContext is undefined

Then, continuing execution, we found that the method/debugger was hit again and this time we got the value in executionContext

This was a strange behavior that custom JS code for Enable Rule of a button got executed twice. To fix this issue, we added null check for executionContext. After adding null check we didn’t get the above error anymore. However, it’s still a mystery that the JS code block/method was getting executed twice.
DisplayReadyForPMU: function (executionContext) { debugger; if (executionContext != null) { var formContext = executionContext.getFormContext(); var campaignType = formContext.getAttribute("sab_outputtype").getValue(); ... } ... }
Hope it helps !!
Reblogged this on Nishant Rana's Weblog.
LikeLike
Hi,
You should also pass these variables to make it work
functionname = function (primaryControl) {
var formContext = primaryControl
LikeLike
Hi Eduard,
Thanks for your input. We are already passing primaryControl “CRM parameter” as the first parameter in the Ribbon Workbench. We have tried using primaryControl as formContext object as you have mentioned. Still we are getting this issue.
LikeLike
I also have the problem that primarycontrol is undefined on onmpremise v9. But the code does not get hit twice.
LikeLike
We were facing this issue on online v9. Are you following the steps as mentioned here https://ajitpatra.com/2018/10/05/d365-v9upgrade-ribbon-button-changes/ and still getting this issue ?
LikeLike
Yes we still getting the issue
LikeLike
The PrimaryControl CRM parameter passed is formContext which can be used further to get the value of the attribute as Eduard has mentioned in one of the comments above.
LikeLike