Answered by:
How to remove "Creating record" infinite loop in plugin

Question
-
I have created asyncronous AuditLog Plugin which will fire on create message for all entities in crm(I have left primary entity field blank while registering plugin). It saves the required details of any record created for any entity in Audit Log Entity. But it goes into infinite loop as it creates record for Audit Log Entity also.
How to make the plugin not fire on AuditLog Entity? and fire for all other entities. ??
Dare to promiseTuesday, July 7, 2009 10:48 AM
Answers
-
Hi, Deepak.
The only way - is to register step for each entity except audit entity.
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com- Marked as answer by D-Virdi Tuesday, July 7, 2009 12:41 PM
Tuesday, July 7, 2009 12:26 PMModerator
All replies
-
Hi Deepak,
You can check IPluginExecutionContext.Depth : http://msdn.microsoft.com/en-us/library/bb959585.aspx and depending upon its value you can prevent the execution.
Regards,
Chinmay
http://metrix.blogspot.com- Proposed as answer by Chinmay Patel Tuesday, July 7, 2009 10:57 AM
Tuesday, July 7, 2009 10:56 AM -
Hi, Deepak.
You can place in the start of your plugin such check:
if (context.PrimaryEntityName == "Your audit entity")
return;
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com- Proposed as answer by Nishant RanaMVP Tuesday, July 7, 2009 11:19 AM
Tuesday, July 7, 2009 11:02 AMModerator -
Thanks for your reply.
ya this solves my problem.
But I have one more query regarding this only.
By using this approach it will check in plugin. this means the plugin will hit every time the audit is created, which should not be like that.
Is there any other way tht I can skip hitting plugin for AuditLog entity and hitting for all other entities??
Dare to promiseTuesday, July 7, 2009 12:25 PM -
Hi, Deepak.
The only way - is to register step for each entity except audit entity.
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com- Marked as answer by D-Virdi Tuesday, July 7, 2009 12:41 PM
Tuesday, July 7, 2009 12:26 PMModerator