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 check for multiple values in an entityReference field

(0) ShareShare
ReportReport
Posted on by 410

Hi Guys,

  I am faced with checking for multiple values in a lookup field, something like the below:

 EntityReference trustRef = clinic.GetAttributeValue<EntityReference>("new_trust");
                    
                    if (trustRef.Name.Trim() == "North  Trust", "walsall", "shewsbury".......)

I Know there is an efficient way to check for this condition. Thanks for the help

*This post is locked for comments

I have the same question (0)
  • Victor Onyebuchi Profile Picture
    410 on at

    , Arun Vinoth Hello my pros, please help your boy out again lol

  • Arun Vinoth Profile Picture
    11,615 Moderator on at

    Did you edit the question with totally different content?

  • Verified answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at

    You have to check like this:

    if (trustRef.Name.Trim() == "North  Trust" || trustRef.Name.Trim() == "walsall" || trustRef.Name.Trim() == "shewsbury" || .......)

    This is ok to certain level, but not a good practice as these are entity references which are entity records, so people may go & rename it. If you think your code should not break, then keep some flag like isPrivileged and mark as true for these records. Then you can query & verify whether the trust lookup in clinic record matches one of that isPrivileged List then proceed.

  • Victor Onyebuchi Profile Picture
    410 on at

    Hi Arun, I havent used isPreviledged on CRM before, really do not know what it is.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Victor,

    It is not a good idea to check for the text/name value of the record. What if someone change the name from "North Trust" to "Norther Trust". You should either check the GUID

    What's the actual requirement you have? I even think that you should not be checking the records at all.

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    btw you are tagging wrong Ravi :)

  • Victor Onyebuchi Profile Picture
    410 on at

    it is a requirement given to us by the client, i believe the name would strictly spelt, that is why i use the trim() method. Hi Ravi, sorry for bugging you,I am pretty new at developing in dynamic CRM (junior developer), can you look at the issue i am also facing ? community.dynamics.com/.../290894 Thanks  

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    No worries Victor. I don't think you a re junior developer now, you have already written so many plugins :)

    Regarding this questions, if you sure that the name will not change then you can use or as suggested above.

    if (trustRef.Name.Trim() == "North  Trust" || trustRef.Name.Trim() == "walsall" || trustRef.Name.Trim() == "shewsbury" || .......)

    Hope this helps. Remember to close the thread once the issue is fixed.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Also I would suggest for best practice  keep those hard code value in an CRM entity (with  Key, Value fields) and retrieve from the entity using key inside plugin instead of hard code. In future if those value chagnes you need to again change your plugin code .

  • Victor Onyebuchi Profile Picture
    410 on at

    @Goutam, the entity contains all other values (the users can enter multiple values), but I want to check for these specific string values to perform an operation, so creating another entity would conflict.

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