Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to validate all the contacts whose status of a custom field(StatusCurrently) value is 'open' in below code

Posted on by 10

var contacts = (from c in _xrmContext.ContactSet
where c.StateCode == ContactState.Active
&& c.EMailAddress1 == dr["EmailAddress"].ToString()
|| c.EMailAddress2 == dr["EmailAddress"].ToString()
|| c.EMailAddress3 == dr["EmailAddress"].ToString()
|| c.email == dr["EmailAddress"].ToString()
&& c.OwnerId.Id != teamId
select c).ToList();

if (contacts.Count > 0)

{

if (contacts[0].StatusCurrently == new OptionSetValue((int)Contact_StatusCurrently.OPEN)) --> I am using contacts[0].StatusCurrently which is reading only first contact from the list. I want to validate all the contacts from the list whose statuscurrently value is 'open'. 

Any help would greatly appreciated  

*This post is locked for comments

  • Venkat457 Profile Picture
    Venkat457 10 on at
    RE: How to validate all the contacts whose status of a custom field(StatusCurrently) value is 'open' in below code

    It works..Thanks for your response!

  • Suggested answer
    Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: How to validate all the contacts whose status of a custom field(StatusCurrently) value is 'open' in below code

    Hello,

    If i understood your question correctly you could either

    a. Iterate through each of them:

    foreach(var contact in contacts)

    {

    if(contact.StatusCurrently == new OptionSetValue((int)Contact_StatusCurrently.OPEN){

    //do logic here

    }

    }

    or you could either use LINQ

    contacts.Where(contact => contact.StatusCurrently == new OptionSetValue((int)Contact_StatusCurrently.OPEN))

    .Foreach(contact =>

    {

    //logic here

    }

    Hope this helps!

    Radu

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans