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
What I meant is adding another bool attribute (isPrivileged) in entity so that you can mark that as true for records like North Trust, Walsall and false for others.
In future if more records added in there or Walsall has to be removed from this check does not need a code change & redeployment.
Simply that bool can be turned off & code will retrieve the records which has value true for that & check dynamically in code.
Otherwise my initial code check will work fine.
@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.
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 .
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.
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
btw you are tagging wrong Ravi :)
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.
Hi Arun, I havent used isPreviledged on CRM before, really do not know what it is.
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.
Did you edit the question with totally different content?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156