Issue-Lookup values getting cleared on Save in Ms Dynamic CRM

What is the issue?

Your application form has some lookup fields on it and you are trying to populate the field via JavaScript. And before save the value seems to be selected/populated on form properly. But when you click on Save button the value in the lookup field disappears and become null. Even on click of Save and close the popup comes and says Unsaved changes on your form.

The Reason-

The issue with Guid that we are setting in lookups.

Solution-

You know the reason now.
Some times we get the Guid in the format-
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

Convert this GUID in the format-
{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}

function SetLookupValue(LookupId, Type, Id, Name) {
    if (Id.indexOf('{') == -1)
        Id = '{' + Id;
    if (Id.indexOf('}') == -1)
       Id = Id + '}';
    Id = Id.toUpperCase();
    var lookupEntityReference = [];
    lookupEntityReference[0] = {};
    lookupEntityReference[0].id = Id;
    lookupEntityReference[0].entityType = Type;
    lookupEntityReference[0].name = Name;
    Xrm.Page.getAttribute(LookupId).setValue(lookupEntityReference);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s