Asked by:
CRM Plugin: Update also the parent entity

Question
-
Hi,
currently i use the default inovice entity and i added a new entity myinvoicedetails. I created a 1:N relation between invoice and myinvoicedetails. Creating records in myinvoicedetails is working totally fine and they are also assigned to the parent invoice.
Then i wrote a plugin on create/update of the myinvoicedetails and i need to update also attributes of the parent invoice.
How can i access the parent invoice. The relation field in the entity myinvoicedetails is also not filled in the Post-Operation stage and also retrieving the myinvoicedetails in the post-operation stage is not filling the relation attribute.
How can i find out to which partent(invoice entity) the myinvoicedetail record is saved ?
Kind Regards
Markus
Thursday, November 28, 2013 12:31 PM
All replies
-
The easiest solution is to register a PostImage on the plugin registration step that includes your relationship attribute; you can access the image in the plugin from the context.PostEntityImages collection
Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
Friday, November 29, 2013 6:36 PMModerator -
Hi,
i registered the PostImage plugin, but the attribute where the relation should be stored ist NULL.
I can get the entity which i am currently working but not the childs and the parents. I tried also in an Post-Operation step to retrieve the written entity, but still the relation attribute is empty.
Kind Regards
Markus
Tuesday, December 3, 2013 9:06 AM -
Hi,
Can you Use post entity Image if the parent record comes in to null you can use plugin target function, it will returns all the fields which are filed data bin will get as a parameter as a entity
Thanks.
Laxman.P
Vinay Kumar.
Tuesday, December 3, 2013 9:18 AM -
Sorry don't understand what you mean with target function.
This is code from the Plugin in the Post-Operation step and in both objects i can not find a link to the parent object.
CrmStronglyTypedClasses.prg_abrechnungsposition => Is class generated with CrmSvcUtil.exe to get a strongly typed class for the entity prg_abrechnungsposition.
CrmStronglyTypedClasses.prg_abrechnungsposition dienstleistungposition = ((Entity)localContext.PluginExecutionContext.PostEntityImages["PostImage"]).ToEntity<CrmStronglyTypedClasses.prg_abrechnungsposition>();
CrmStronglyTypedClasses.prg_abrechnungsposition dienstleistungposition2 = ((Entity)localContext.PluginExecutionContext.InputParameters["Target"]).ToEntity<CrmStronglyTypedClasses.prg_abrechnungsposition>();
Wednesday, December 4, 2013 2:24 PM