web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Validate null check in plugin UCI - 9.0

(1) ShareShare
ReportReport
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
    MuhammadUsmankhan_dev Profile Picture
    25 on at

    Do it like this hopefully it will work.

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

    {

    //perform logic

    }

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at

    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
    Bipin D365 Profile Picture
    28,995 Moderator on at

    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

    }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 89 Most Valuable Professional

#2
11manish Profile Picture

11manish 69 Super User 2026 Season 2

#3
Travis South Profile Picture

Travis South 45

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans