web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Defaulting look up field after filtering the lookup view

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Wayne Walton Profile Picture

Wayne Walton 2

#2
Good.Panos Profile Picture

Good.Panos 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans