Wednesday 3 July 2013

MSCRM 2011 - Disable fields based on Lookup Change - Retrieve Lookup Values using Javascript


Right now i am going to brief about retrieving value from MSCRM lookup field and disabling the other fields based on Lookup change.

Scenario :

I have a lookup, in which i want to disable other field whenever the lookup value is selected as "Country". Here the sample script.

//Code Starts
var lookupItem = new Array;

if (Xrm.Page.getAttribute("lookupfieldid").getValue())
{

    lookupItem = Xrm.Page.getAttribute("lookupfieldid ").getValue();

    if (lookupItem[0] != null)
    {
        if (lookupItem[0].name == "Country")
        {
            Xrm.Page.getControl("fieldname").setDisabled(true);
        }
        else
        {
            Xrm.Page.getControl("fieldname").setDisabled(false);
        }
    }


}

//Code end.

Add the above code on the Lookup field on change event.

To know about working on other CRM fields, please visit my previous post.

Feel free to post you comments if you need any help.

No comments:

Post a Comment