Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Check , Attribute is not available in entity using IF condition

Posted on by 1,000

I can retrieve the entity in objRecord variable.

Entity objRecord = service.Retrieve(<here retrieve>)

If the value available in new_fieldname it will return in objRecord . so i will check like the following,

if (objRecord .Attributes.Contains("new_fieldname"))
{

}

How can I check the new_fieldname  Does not have value? don't want to check in else part  i need to check only in IF condition? how can I do this ? Is it possible ?

*This post is locked for comments

  • Suggested answer
    Alagunellaikumar Profile Picture
    Alagunellaikumar 6,210 on at
    RE: Check , Attribute is not available in entity using IF condition

    IF you find answer could you please mark as verified

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Check , Attribute is not available in entity using IF condition

    Hello,

    Try following:

    if (!objRecord.Attributes.Contains("new_fieldname"))

    {

    }

  • vijay12872 Profile Picture
    vijay12872 1,000 on at
    RE: Check Attribute is not available in entity using IF condition

    I need to achieve like the following scenario

    if (objRecord .Attributes.DoesnotContain("new_fieldname"))

    {

    }

    But Unfortunate  we cant check use the above code. how can I do it in alternative way

  • Alagunellaikumar Profile Picture
    Alagunellaikumar 6,210 on at
    RE: Check Attribute is not available in entity using IF condition

    Hi

    Based on field data type the condition check will be differ. Please find below how to check condition with different datatype.

    if (objRecord .Attributes.Contains("new_fieldname"))

    {

    //String

    if(string.IsNullOrEmpty(objRecord .Attributes["new_fieldname"])

    //EntityReference

    EntityReference objEntityReference=(EntityReference)objRecord .Attributes["new_fieldname"];

    if(objEntityReference!=null && objEntityReference.Id!=null)

    //Int

    if(objRecord .Attributes["new_fieldname"]!=0)

    }

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans