Reputation: 1993
I have a plugin which is fired on the Pre Operation Update of the Incident entity. The filtered attribute is new_SecureIncident.
As part of the plugin execution, I create a new record in another entity called Secure Access (this entity has a Look up to Incident entity).
Also, as part of this Pre Operate, I update a particular field new_DocumentSetURL on Incident entity.
This is how I set it.
Incident incidentBeforeUpdate = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.PreImageAlias)) ? context.PreEntityImages[this.PreImageAlias].ToEntity<Incident>() : null;
Incident incident = (context.InputParameters != null && context.InputParameters.Contains(Target) && context.InputParameters[Target] is Entity) ? ((Entity)context.InputParameters[Target]).ToEntity<Incident>() : null;
I later update the value of new_DocumentSetURL as below
incident.new_DocumentSetURL = incidentDocumentURL;
Now, I also have a Post Operation Create Plugin on the Secure Access entity.
Problem:
The Plugin on Secure Access still has the old value of the new_DocumentSetURL. How can I organize my plugins so that the create plugin on Secure Access entity picks up the correct DocumentSetURL value?
Full Process Description
The Pre Update on Incident calls a Web Service to SharePoint. This WCF web service call takes as input paramters the DocumentSetURL value and returns a modified one. I update Incident with the modified DocumentSetURL.
Then, I create a new Secure Access record. This again makes a call to the WCF web service and it takes two parameters, the DocumentSetURL (of the lookup on Secure Access) and the name (primary attribute) of Secure Access.
Please note that the Secure Access records can also be created manually. So, I am just calling the service.Create(new_secureaccess)
and not writing the functionality of PostCreate of Secure Access within the PreUpdate of Incident.
That way, I would have to write only once the PostCreate of Secure Access and it would be called irrespective of whether it is manually created or automatically created (by the PreUpdate of Incident plugin).
Upvotes: 2
Views: 1130
Reputation: 6558
It sounds like the problem may be the order of operation.
You are creating the Secure Access record in the PreOp stage of the Incident, so the value you set for incident.new_DocumentSetURL
has not yet been submitted to the database; hence your attempts to retrieve this attribute from the linked Incident of your newly created Secure Access record only "knows" about the old record.
Instead, move the logic which creates the Secure Access record to the PostOp of the incident. This will be after your changes to incident.new_DocumentSetURL
have been saved to the database.
If you wanted, you could move the entire logic you have in the PreOp of Incident to the PostOp (so all logic will be in one spot), but this would require you to make a call to service.Update(incident)
after setting the value due to the processing stage. If you go this route though, make sure you update the Incident before creating your Secure Access record (so the order of operation doesn't come into play).
Upvotes: 1