Answered by:
merging plug-ins on same entity

Question
-
Hi All,
I need to write some code to do the following two things on SalesOrder entity
1) On Creation(one time only) - Do some maths and populate some custom attributes based upon information provided by user
2) On Update( Every Save event) - Check if some certain fields being updated, update all the order items with those values.
I have written a Plug-in which triggers upon "Create" Message and its working fine.
I have written the second plug-in which triggers upon "Update" Message which is not working and giving me the error
"The given key was not present in the dictionary"
When I looked into the trace, I believe that its not getting the "id" property from the OutPutParameters prpoerty bag.
string orderid = context.OutputParameters.Promoerties["id"].toString();
I believe its because the update is get called (service.Update(entity) in 1st stage within the Plug-in (Create Message) and its not forwarding the "id" property OR because the "id" property has not been changed so its not in the Propertybag.
How can I get the "id" ("salesorderid") property value in the Update Plug-in code?
My question is what's the best way to write something against these events (Create, Update) and can we merge it into single code or not.
Thanks in advance
AMTuesday, November 30, 2010 2:36 PM
Answers
-
you need to use Images in your update plugin
http://inogic.blogspot.com/search/label/Pre-Image
http://nishantrana.wordpress.com/2008/07/11/preentity-and-postentity-images-in-crm-40/
Mahain : My Dynamics CRM Blog- Proposed as answer by Jim Glass Jr Tuesday, November 30, 2010 7:48 PM
- Marked as answer by DavidJennawayMVP, Moderator Tuesday, February 15, 2011 4:31 PM
Tuesday, November 30, 2010 2:49 PMModerator -
Maybe too late for the original poster, but for reference, in the Update plugin you get the primary key from the InputParameters collection:
DynamicEntity de = (DynamicEntity) context.InputParameters["Target"];
string orderid = ((Key) de.Properties["salesorderid"]).Value.ToString();
Microsoft CRM MVP - http://mscrmuk.blogspot.com http://www.excitation.co.uk- Marked as answer by DavidJennawayMVP, Moderator Tuesday, February 15, 2011 4:31 PM
Tuesday, January 25, 2011 11:28 AMModerator
All replies
-
you need to use Images in your update plugin
http://inogic.blogspot.com/search/label/Pre-Image
http://nishantrana.wordpress.com/2008/07/11/preentity-and-postentity-images-in-crm-40/
Mahain : My Dynamics CRM Blog- Proposed as answer by Jim Glass Jr Tuesday, November 30, 2010 7:48 PM
- Marked as answer by DavidJennawayMVP, Moderator Tuesday, February 15, 2011 4:31 PM
Tuesday, November 30, 2010 2:49 PMModerator -
Maybe too late for the original poster, but for reference, in the Update plugin you get the primary key from the InputParameters collection:
DynamicEntity de = (DynamicEntity) context.InputParameters["Target"];
string orderid = ((Key) de.Properties["salesorderid"]).Value.ToString();
Microsoft CRM MVP - http://mscrmuk.blogspot.com http://www.excitation.co.uk- Marked as answer by DavidJennawayMVP, Moderator Tuesday, February 15, 2011 4:31 PM
Tuesday, January 25, 2011 11:28 AMModerator