I have a plugin that run on update of look up field. So basically, when a look up is filled with any record, the plugin will get the GUID from the record inside the look up field and do some logic with it's GUID.
Now i want to make this plugin keep run but doing nothing when the record inside the look up field is deleted. When i delete the record inside the look up, it's show an error says "object reference not set to an instance of an object". Cos my plugin unable to get any records from the look up field.
In short, before the plugin doing some logic, i want to check wheter the look up is empty or not.
I have tying this, but still it's show the same error message:
public void Execute(IServiceProvider provider) { IPluginExecutionContext context = (IPluginExecutionContext)provider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService _service = factory.CreateOrganizationService(context.UserId); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName != "lnkt_troubleticket") return; if (entity.Attributes.Contains("lnkt_mainticketid"))//name of the look up field { Guid referal_id = Guid.Empty; referal_id = (entity.GetAttributeValue<EntityReference>("lnkt_mainticketid")).Id; //get look up data if(referal_id != null){ // Do some logic } } } }
How to avoid this ?
My plugin run on Pre-Operation with Update Message (Look up)
*This post is locked for comments