0
votes

I'm working on a Microsoft Dynamics CRM 2011 plugin attached to SalesOrder entity on Create event. I need to get the Order parent Account, to access some of its properties. I'm trying the following code inside the Execute method, but key "accountid" is not present at time of execution.

Entity entity = (Entity)context.InputParameters["Target"]; // A salesorder entity
EntityReference accountRef = (EntityReference)entity.Attributes["accountid"];

Plugin is registered at Post-operation stage to execute in synchronous mode. Following image show all configuration.

Plugin Registration Config

Is there another way to get the parent Account for the SalesOrder entity?

2

2 Answers

2
votes

It seem to be an error on the SDK documentation, because the accountid attribute is never available for the salesorder entity, even if I configure the plugin to run in Asynchronous mode. I ended changing the accountid attribute by customerid, which in fact can be an account (default behavior). That solved my problem and I could get a reference to the Account which Order belongs.

Entity entity = (Entity)context.InputParameters["Target"]; // A salesorder entity
EntityReference accountRef = (EntityReference)entity.Attributes["customerid"];
if (accountRef.LogicalName != "account") return;
0
votes

There are two possible issues here. First, is your plugin registered in Synchronous execution mode with Pre-Operation eventing pipeline stage of execution? Check out this settings, problem is probably there.

Second, if you correctly registered plugin, maybe you didn't set ParentAccount on SalesOrder form, which is probably not an issue :)