Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Dynamics CRM 2015 Plugin - Update Sales Order through SDK

$
0
0

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.

protectedvoid ExecutePostOrderCreate(LocalPluginContext localContext)

{

if (localContext == null)

{

thrownewArgumentNullException("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"] isEntity&& _context.Depth < 2)

{

var targetEntity = (Entity)_context.InputParameters["Target"];

if (targetEntity.LogicalName == "salesorder")

{

SalesOrder mySalesOrder = (SalesOrder)service.Retrieve(SalesOrder.EntityLogicalName, targetEntity.Id, newColumnSet(true));

mySalesOrder.Name += " Test";

service.Update(mySalesOrder);

}

}

}


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images