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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how to check for a specific value in a lookup field?

(0) ShareShare
ReportReport
Posted on by

I'm attempting to check for a value via a lookup field, and if the value is the value I am looking for, make another field on the form required.

The second part is no problem, it's the checking to see if a specific value for the lookup was selected.

I'm using dynamics crm 2011 on premise and I've done a lot of research, finding a lot of different code, I either get an error or when I input an alert I get prompt saying [object Object] from the code below.. Please help!

function namelocationrequired() {
 
  var lookup = Xrm.Page.getAttribute("new_csiapprovedtradeshows").getValue();

 
 /*
             if (lookup != null) {
                 var name = lookup[0].name;
                 var id = lookup[0].id;
                 var entityType = lookup[0].entityType;

                          alert(name);
                          alert(id);
                          alert(entityType);  
   
                    }
 */
 
                alert(lookup);


    }

*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    How do you plan to compare - by id or name? If you want to compare by id you can use something like:

    var lookup = Xrm.Page.getAttribute("new_csiapprovedtradeshows").getValue();
    
    if (lookup == null){
    //lock your second field here
    return;
    }
    
    if (lookup[0].id == "Your guid for comparing here"){
    //unlock your second field here
    } else {
    //lock your second field here
    }


    For name you can use almost the same code changing lookup[0].id to lookup[0].name

  • Community Member Profile Picture
    on at

    Andrii I switched id out with name, the name is 'Other Trade Show Not Listed'

    I don't really need to look for a null value since it's an onChange event do I? Can I remove that part of the code?

    I'm testing now. Thanks!

  • Community Member Profile Picture
    on at

    never mind I think I understand now. If lookup equals null I need to set new_othertradeshownameandlocation to not required.

  • Community Member Profile Picture
    on at

    ANDRII Thank you! With your help, I got it to work properly!

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
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans