Darren Lewis
Darren Lewis

Reputation: 8498

Plugin not firing on status change of Order

Anyone know of any reason a plugin registered for SetState and SetStateDynamicEntity isn't firing on salesorder? If I register for Update against statecode it fires correctly.

I've tried registering in all different stages in the pipeline, iisreset, unregister/register without success. Also checked it fires correctly for these messages against a different entity, which it does.

Checked the spreadsheet in the SDK and they're valid messages for salesorder. I know that an orderclose activity is also created "under the hood" so wasn't sure if there was something else at play here in respect of the whole order proces?

In this instance I can achieve what I want by registering the Update message against the statecode attribute. However, I'd like to understand the reason for this behaviour.

Upvotes: 0

Views: 2919

Answers (1)

Guido Preite
Guido Preite

Reputation: 15138

I tried with a simple plugin (just throw an InvalidPluginExecutionException) and actually the plugin is not fired if registered on SetState or SetStateDynamicEntity.

Looking at MSDN I found this example:

Sample: Fulfill a Sales Order

It uses the message FulfillSalesOrderRequest in this way:

// Close the sales order with a status of Complete
int newStatus = (int)salesorder_statuscode.Complete;
var request = new FulfillSalesOrderRequest
{
    OrderClose = new OrderClose
    {
        SalesOrderId = new EntityReference 
            { LogicalName = SalesOrder.EntityLogicalName, Id = _salesOrderId.Value }

    },
    Status = new OptionSetValue(newStatus)
};

and inside the MSDN for the FulfillSalesOrderRequest Class

http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.fulfillsalesorderrequest.aspx

is written:

Privileges and Access Rights
To perform this action, the caller must have privileges on the OrderClose entity and access rights on the records specified in the OrderClose property.
For a complete list of required privileges, see FulfillSalesOrder Privileges.

After I registered my plugin on Create step for OrderClose entity (Pre-operation stage) and it works (throwing me the exception) when I try to fulfill an order.

Looks like this is the suggested way (at least from MSDN) to intercept the fulfill of an order.

Upvotes: 3

Related Questions