Cancel delete using PreDelete callout.

Just an example of using PreDelete callout !!!

public override PreCalloutReturnValue PreDelete(CalloutUserContext userContext,
   CalloutEntityContext entityContext,
   ref string errorMessage)
  {
   
   // Use retrive to get the status value
   CrmService service=new CrmService();
   service.CallerIdValue=new CallerId();
   service.CallerIdValue.CallerGuid=userContext.UserId;
   service.Credentials=System.Net.CredentialCache.DefaultCredentials;

   // Get status value
   ColumnSet cols=new ColumnSet();
   cols.Attributes=new String[]{“statuscode”};

   BusinessEntity busEntity= service.Retrieve(EntityName.salesorder.ToString(),entityContext.InstanceId,cols);

   salesorder poOrder=(salesorder)busEntity;
   // check for PO status value
   string poStatusValue=poOrder.statuscode.Value.ToString();

   // if status is found cancel the event and show error message
   if(poStatusValue==1)
   {
    errorMessage = “Aborting delete : Record cannot be deleted !”;
    return PreCalloutReturnValue.Abort;
   }
   
   return PreCalloutReturnValue.Continue;
  }

 Bye…


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

1 thought on “Cancel delete using PreDelete callout.”

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s