primarycontrol Archives - Microsoft Dynamics 365 Blog https://microsoftdynamics.in/tag/primarycontrol/ Microsoft Dynamics CRM . Microsoft Power Platform Sat, 22 Aug 2020 13:26:24 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.1 https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/cropped-Microsoftdynamics365-blogs.png?fit=32%2C32&ssl=1 primarycontrol Archives - Microsoft Dynamics 365 Blog https://microsoftdynamics.in/tag/primarycontrol/ 32 32 176351444 Error : getFormContext is not a function in UCI , Ribbon Button https://microsoftdynamics.in/2020/08/22/error-getformcontext-is-not-a-function-in-uci-ribbon-button/ Sat, 22 Aug 2020 13:26:24 +0000 http://microsoftdynamics.in/?p=4089 The post Error : getFormContext is not a function in UCI , Ribbon Button appeared first on Microsoft Dynamics 365 Blog.

]]>

When passing primaryControl in Ribbon WorkBench we use it as executionContext and then get FormContext out of it.

But when same thing is done on UCI we get the Error getFormContext is not a function

We got this error in UCI and not in Legacy WebClient,

  1. We were Passing CRM Parameter PrimaryControl to Button in Ribbon workbench

  2. In JS we were getting FormContext from primaryControl(Executioncontext) which was working fine in the Legacy app

    function readXML(primaryControl) {   
    var formContext  = null;
     if (primaryControl!== null) { 
                formContext = primaryControl.getFormContext(); 
             }
        }
    }
  3. But when same is called in UCI we get ” ” Script Error, Because here we need to treat primary control as formContext

So final change needed in Code is as below

function readXML(primaryControl) {   
var formContext  = null;
 if (primaryControl!== null) {
         if (typeof primaryControl.getAttribute === 'function') {
             formContext = primaryControl; //called from the ribbon.
         } else if (typeof primaryControl.getFormContext === 'function' 
                 && typeof(primaryControl.getFormContext()).getAttribute === 'function') {
            formContext = primaryControl.getFormContext(); // most likely called from the form via a handler
         }
    }
}

The post Error : getFormContext is not a function in UCI , Ribbon Button appeared first on Microsoft Dynamics 365 Blog.

]]>
4089