
Hi,
I have a requirement, in which i need to first filter records based on condition for the lookup field and then set that lookup field with the filtered record.
Basically custom filter view will return only one record in my requirement. I am able to set a custom view as default by using javascript, but I don't how to set that filtered record as default to lookup. Appreciate your help.
*This post is locked for comments
I have the same question (0)You can use the Xrm.Page.getAttribute(lookupName).setValue() to set the value of the lookup.
You will need to know the Guid, Name and entityName of the record that you want to set as default.
You can use the following helper function to set the default value:
// fieldname = The name of the lookup attribute on the entity form
// lookupId = the unique identifier (Guid), of the lookup record you want to set as default
// lookupName = The display name of the lookup record you want to set as default. For example if the lookup is to the account record, this would be the value of the name field of the account record
// entity name = The name of the entity the lookup references. Such as account.
function setLookupField(fieldName, lookupId, lookupName, entityName) {
var lookupData = new Array();
var lookupItem = new Object();
lookupItem.id = lookupId;
lookupItem.name = lookupName;
lookupItem.entityType = entityName;
lookupData[0] = lookupItem;
Xrm.Page.getAttribute(fieldName).setValue(lookupData);
}
Hope this helps.