Please wait, loading...

 

Error : getFormContext is not a function in UCI , Ribbon Button

August 22, 2020

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
         }
    }
}
https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651
Microsoft Dynamics Community Profile

Learn more