web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Defaulting look up field after filtering the lookup view

(0) ShareShare
ReportReport
Posted on by

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

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans