Recently in one of our projects, where we were using the auto number attribute (with sequential numbers), we realized that it gets incremented even in case of an exception thrown during Pre Stage of the Plugin Execution. We were assuming the number gets incremented only after the record gets created i.e. on post-stage.
But as the documentation mentions, the number gets pre-selected as soon as the record is started.
Let us see it in action also –
Here we have the lead record created with My Autonumber as the auto number column with seed as 1000
The auto number field has a value of 1009 currently.
Now let us register a plugin on the Pre-Create stage that throws the exception.
Let us try creating a new lead record, which as expected will throw the exception.
Let us try saving the record 3 times more, triggering the record creation as well as the plugin along with the exception.
Now let us disable the plugin step and save/create the record.
As expected the record gets created, and the auto number field has a value of 1014.
The same behavior was observed in case of Pre-Validation stage.
Hope it helps..
2 thoughts on “Autonumber field values in case of exception in Dynamics 365 / CRM”