Monday, 9 July 2018

Get formContext in Ribbon Command - Dynamics 365 9.0

Hi,

We all know that there are lot of changes to Dynamics 365 JavaScript in accessing form attributes and controls. We should pass executionContext to a function and get the formContext. We can easily the context for onLoad, onChange and onSave events and the problems when we need to get in the functions that are configured to trigger on the Ribbon button click event.

We have a way to solve this issue by passing PrimaryControl as a CrmParameter to the function and in Javascript function pass parameter like below and getFormContext from the parameter what we passed. 




function mySampleFunction(primaryControl) {
            var formContext = primaryControl.getFormContext();
            formContext.ui.controls.get("name").getAttribute().setValue("123")
        }


Hope this helps. 

--
Happy CRM'ing
Gopinath