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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin Triggered by lookup field

(0) ShareShare
ReportReport
Posted on by

Hi guys, i have plugin that triggered by lookup, when lookup value is change, the plugin will execute some logic. But this also cause problem when i clear/set to empty the lookup value, its returning object reference not set to an object. How to avoid this, i mean when the lookup value is set to empty. Just avoid the logic. The plugin registered on Update Message

Entity e = (entity)context.InputParameters["target"];


if(e.Attributes.Contains("new_lookup"){

  Guid lookup_value = (e.GetAttributeValue<EntityReference>("new_lookup)).Id;

  if(lookup_value != Guid.empty){
    //Do Logic
  } 

}


*This post is locked for comments

I have the same question (0)
  • gdas Profile Picture
    50,091 Moderator on at

    Hi,

    In this case the plugin should be registered deassociate message.

  • Suggested answer
    Ben Thompson Profile Picture
    6,350 on at

    When you sent an lookup to be empty the returned entity reference itself is null not just the id within the entity reference.

    You need something like

    if (e.Contains("new_lookup") && e.GetAttributeValue<EntityReference>("new_lookup")!=null)){
    
    
    
    }


  • Suggested answer
    BadrinathB Profile Picture
    970 on at

    Hi Fikri,

    Please add a null check as well.

    Entity e = (entity)context.InputParameters["target"];

    if((e.Attributes.Contains("new_lookup") && e.GetAttributeValue<EntityReference>("new_lookup))!= null){

     Guid lookup_value = (e.GetAttributeValue<EntityReference>("new_lookup)).Id;

     if(lookup_value != Guid.empty){

       //Do 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

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans