Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    BadrinathB Profile Picture
    970 on at
    RE: Plugin Triggered by lookup field

    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

     }

    }

  • Suggested answer
    Ben Thompson Profile Picture
    6,350 on at
    RE: Plugin Triggered by lookup field

    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)){
    
    
    
    }


  • gdas Profile Picture
    50,091 Moderator on at
    RE: Plugin Triggered by lookup field

    Hi,

    In this case the plugin should be registered deassociate message.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans