Announcements
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.
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
}
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
Do it like this hopefully it will work.
if(targetEntity.Attributes.Contains("customernumber") && targetEntity.Attributes["customernumber"]!=null)
{
//perform logic
}
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156