Skip to main content

Notifications

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
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 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 8,596 Super User 2024 Season 1 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

News and Announcements

Announcing Category Subscriptions!

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans