Monday, February 25, 2013

Passing custom parameters through XRM Utility functions


As you all know that Microsoft included Xrm.Utility Functions in its Rollup 8 for Microsoft Dynamics CRM 2011 for both online and on- premises:

Function
Description
openEntityForm
Opens an entity form
openWebResource
Opens an HTML web resource.


But when trying to pass custom parameters to OpenEntityForm as mentioned by MSDN link, I get CRM Error page:






Hence I had to do a work around to pass the custom parameters to OpenEntityForm. I need to pass the custom parameter to new Account form opened through xrm.utility.  Here are the steps:

1. Configure parameters in Entity Form:
Configure custom parameter in the Entity form:
Name: IS_Flag
Type: SafeString



2. Setting custom parameters for OpenEntityForm function:

function openNewAccount() {
    //set the parameters to pass to the new form 
    var parameters = {}, flag = false;
    var regardingField = Xrm.Page.getAttribute("regardingobjectid").getValue();
    if (regardingField[0].id != null) {
        flag = "true";
    }
    parameters["Is_Flag"] = flag;
    //Open the new form
    Xrm.Utility.openEntityForm("account", null, parameters);
}

3. Retrieving the custom parameters in entity form:
function OnFormLoad() {
    // Get the Value of the Regarding through the Customer Parameters
    var param = Xrm.Page.context.getQueryStringParameters();
    var RetrivedParameter = param["Is_Flag"];
    if (RetrivedParameter != null) {
        Xrm.Page.getAttribute("new_IsContactchecked").setValue(RetrivedParameter);
    }
}

This way you will be able to retrieve the custom parameter value in the newly opened CRM form.

Hope this was helpful !!!

No comments:

Post a Comment