SBX - Search With Button

SBX - Forum Post Title

Plugin Output Parameters

Microsoft Dynamics CRM Forum

Bhanu Prathap Thouta asked a question on 2 Jun 2016 6:31 AM
My Badges

Question Status

Verified

In the example code given by microsoft in followup plugin (link below)

https://msdn.microsoft.com/en-us/library/gg594416.aspx

there is a code line which tries to attach account as regardingobject to the task which will be created.

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

Why is that Output parameters are used to get the ID of the initiating entity when you can
get it easily by entity.Id from Target.

Thanks.


Reply
Tom S responded on 2 Jun 2016 8:12 AM
My Badges

Bhanu,

Not sure without testing, but because this is a plug-in to be executed on create of account, it's possible the id would not exist yet. The create output is a new account with an id.  If this were a workflow activity the account would likely exists depending on how the workflow is called.   Again, not sure without testing though.

Best Regards,

Tom.

Reply
Suggested Answer

Hi,

The OutputParameters will contain the Response object properties - so for a Create Request, it will contain the Create Response properties - which is why it contains the id property that will be returned by the platform - msdn.microsoft.com/.../microsoft.xrm.sdk.messages.createresponse.id.aspx

For more information see msdn.microsoft.com/.../gg309673.aspx

Hope this answers your question!

Reply

Hi,

Do you need any more help from Tom or I?

Reply
Bhanu Prathap Thouta responded on 6 Jun 2016 4:38 AM
My Badges

Hi Scott,

Just wanted to verify my understanding regarding this.

Scenario : A plugin is written on Create message of a entity A. Through this plugin I would like to add a task and attach it to the created entity record. So I will need the ID of the created record.

According to your explanation, for a create message, id is found in output parameters as it is a response object but not in input parameters.

I tried getting entity.PrimaryEntityID in the same context. Below are the results.

context.PrimaryEntityId : d736d2f5-c92b-e611-80ca-448a5bb3f17f

(context.OutputParameters["id"].ToString()) --->  d736d2f5-c92b-e611-80ca-448a5bb3f17f

My question still remains the same. Why does the official microsoft code get id from outputparameters when you can easily get from context.PrimaryEntityId in general. Is it due to any performance enhancement?

Reply
Bhanu Prathap Thouta responded on 6 Jun 2016 4:42 AM
My Badges

Look into my reply above.

Additionally, Tom and Scott

i have got the id from both ways, interested in knowing the recommended way and why.

I observed while debugging that, entity on which I have registered the plugin won't be created when I am running a profiler. Post create plugin error will restrict from creating the record ? Can we say this.

Reply
Verified Answer

Hi,

The OutputParameters["id"] will only be populated on the Post Pipeline stage - it isn't present in the Pre stage. I think the SDK sample is using the id because it's intended to be registered at the Post stage and the OutputParameters are immutable and so will always give you what was applied in the transaction.

There isn't any performance gain over the context.PrimaryEntityId or indeed ((Entity)InputParameters("Target")).Id - they would all return normally the same.

Hope this answers your question?

Reply
Verified Answer

Hi,

The OutputParameters["id"] will only be populated on the Post Pipeline stage - it isn't present in the Pre stage. I think the SDK sample is using the id because it's intended to be registered at the Post stage and the OutputParameters are immutable and so will always give you what was applied in the transaction.

There isn't any performance gain over the context.PrimaryEntityId or indeed ((Entity)InputParameters("Target")).Id - they would all return normally the same.

Hope this answers your question?

Reply
Suggested Answer

Hi,

The OutputParameters will contain the Response object properties - so for a Create Request, it will contain the Create Response properties - which is why it contains the id property that will be returned by the platform - msdn.microsoft.com/.../microsoft.xrm.sdk.messages.createresponse.id.aspx

For more information see msdn.microsoft.com/.../gg309673.aspx

Hope this answers your question!

Reply

SBX - Two Col Forum

SBX - Migrated JS