Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Validate null check in plugin UCI - 9.0

Posted on by 20

Dears,  

I am trying to validate a null check like below in the plugin,

if(targetEntity.Attributes.Contains("customernumber"))

{

//perform logic

}

In classic form above logic works fine and if the customer number is null then it stops the further execution within if block.

However, the same logic does not work in UCI environment somehow which I suppose is a bug from Microsoft. 

I am firing plugin on create. Is there any way to fix this without modification within plugin.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 Moderator on at
    RE: Validate null check in plugin UCI - 9.0

    Hello,

    You will have to modify your code to fix this issue.

    Try below code -

    if(targetEntity.Attributes.Contains("customernumber") && targetEntity["customernumber"]!=null)

    {

    //perform logic

    }

  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 6,407 Moderator on at
    RE: Validate null check in plugin UCI - 9.0

    Hello Farah,

    You can add below code which will help you to check null condition.

    if(targetEntity.Attributes.Contains("customernumber") && targetEntity.Attributes["customernumber"] != null)
    {
    
    //perform logic
    
    }

    basically Contains() will help to verify if the Entity contains an attribute with the specified name or not. and if it contains the given field then it will return true else false.

    Then next condition will check if the field value is null or not.

    It is possible that if you are not applying try and catch in your code then your plugin will show exception to the users if any error occurs. to avoid it you can add try and catch in your plugin code.

    Thank you,

    Amit katariya

  • Suggested answer
    RE: Validate null check in plugin UCI - 9.0

    Do it like this hopefully it will work.

    if(targetEntity.Attributes.Contains("customernumber") && targetEntity.Attributes["customernumber"]!=null)

    {

    //perform logic

    }

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans