0
votes

I have a plugin for Microsoft Dynamics CRM 2011 that fires when i update a student entity.

Every student record is binded to a contact record. Based on firstname, lastname and emailaddress. So when one of these fields is changed on update, a new contact record must be created to match the student.

Then, on the student form, this new contact must be autofilled in the contact lookup field.

I've written code to do this, but then i when i try service.Update(entity) it fails.

Thanks for any help!

1
the line "service.Update(entity)" throws up an FaultException. "An error occured in plugin". So everything goes fine before that line...ThdK
If you comment out your try/catch, you'll see the "real" error that is being thrown...Josh Painter

1 Answers

3
votes

You've registered this plugin to execute on the Update event of the Student entity, correct? Then, chances are the exception you're getting is going to be a complaint about an infinite loop... because you're triggering another update from within your update. Your service.update call starts the update pipeline on the given record all over again.

If you click the 'download log file' link on the error dialog that CRM is popping up, check the Message and the InnerFault fields to see if additional further info is included.

CRM keeps track of the call stack depth during plugin calls, and will throw the 'infinite loop' fault if the depth limit is exceeded. (See articles here and here.)

If you must update the current record during an update, there are a couple of workarounds: either check the call stack depth at the start of your plugin and do nothing if it's over an expected value (not the ideal solution but it does work), or check for the present (or absence) of an expected attribute and code accordingly. For example, in your scenario you might compare the ave_contactid attribute in the preMessageImage object against the postMessageImage object. If this field is in the process of changing, don't change it again in your plugin.