Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Defaulting look up field after filtering the lookup view

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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 Profile Picture
    Aric Levin 30,188 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,791 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,488 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans