简体   繁体   中英

Dynamics CRM Plugin - setting a related record

I am writing a plugin which fires on the PostCreation of an invoice. This plugin creates a commission record and is supposed to set a lookup field on the commission record which points to the newly created invoice. However there seems to be no value for the Guid of the invoice while the plugin runs - I assume it only gets a Guid once it is committed to the database?

Is there a way in which I can get the Guid of the new invoice or even set it manually, so that I know what it will be before the plugin ends?

Thanks

Inside a Plugin it is possible to access to the OutputParameters only when the step is registered in asynchronous mode or in synchronous mode post-event.

From MSDN - Understand the Data Context Passed to a Plug-In

However, only synchronous post-event and asynchronous registered plug-ins have OutputParameters populated as the response is the result of the core platform operation

Because you registered the step as post-event you can use Daryl's code (the right property is id lower case)

From MSDN - Sample: Basic Plug-In

Register this plug-in for an account entity, on the Create message, and in asynchronous mode. Alternately, you can register the plug-in on a post-event in the sandbox.

In the basic plugin example there is a warning about the execution mode, because the code uses the OutputParameters collection, but it's not explained why.

The code in this example is:

Guid regardingobjectid = new Guid(context.OutputParameters["id"].ToString());

As long as you are in the Post Creation step of the Invoice, the Guid should be there.

Where are you looking for it? Have you tried this:

Guid id = (Guid)context.OutputParameters["id" ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM