Hello,
I have a plugin registered on the Sales Order Entity with Message 'Create' on Stage 'PostOutsideTransaction' and in mode 'Synchronous'.
In the execute method that is fired upon the creation of the Sales Order Entity, I am trying to perform a very basic update.
Below is an example of the code.
When this plugin triggers, I can step through the code and it reaches the line of service.Update(mySalesOrder).
Upon the execution of this line, I am gifted an error message stating 'Object reference not set to an instance of an object'.
Any help with this would be greatly appreciated.
For what it's worth too... I do have code that can add sales order details to this sales order and it works just fine... so I am not sure why I cannot perform a simple update on the sales order itself.
protected void ExecutePostOrderCreate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IServiceProvider _service = localContext.ServiceProvider;
OrganizationServiceProxy _org = (OrganizationServiceProxy)localContext.OrganizationService;
IPluginExecutionContext _context = localContext.PluginExecutionContext;
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)_service.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(_context.UserId);
if (_context.InputParameters.Contains("Target") && _context.InputParameters["Target"] is Entity && _context.Depth < 2)
{
var targetEntity = (Entity)_context.InputParameters["Target"];
if (targetEntity.LogicalName == "salesorder")
{
SalesOrder mySalesOrder = (SalesOrder)service.Retrieve(SalesOrder.EntityLogicalName, targetEntity.Id, new ColumnSet(true));
mySalesOrder.Name += " Test";
service.Update(mySalesOrder);
}
}
}
*This post is locked for comments