web
You’re offline. This is a read only version of the page.
close
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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans