Locking mechanism for auto-numbering functionality for Microsoft Dynamics CRM RRS feed

  • Question

  • Hello,

    I have implemented auto-numbering functionality for Microsoft Dynamics CRM and I am trying to add the locking mechanism to it. I am using c# plugin on create of an entity to assign the auto-number to the entity, based on a custom configuration entity record for the entity. Is there any way to add locking mechanism for auto-numbering functionality?

    • Edited by P H S Wednesday, August 5, 2015 6:49 AM
    Wednesday, August 5, 2015 6:45 AM

All replies

  • Hello,

    Could you please explain what do you mean telling "locking mechanism"?

    Dynamics CRM MVP
    My blog

    Wednesday, August 5, 2015 7:58 AM
  • I am using a custom entity as configuration entity which will store information like entity, entity field (for which auto-number needs to be assigned), the number to be assigned, etc. So, when I try to create 2 entity records (for which auto-number functionality is enabled) at the same time, the same auto-number is getting assigned to both the records. So my requirement is I want to lock the record, update the seed number first and then only assign the updated auto-number to the second record.
    Wednesday, August 5, 2015 10:03 AM
  • Do you use CRM Online or On-Premice?

    For onpremice you can use following trick:

    1. Reference static object like

    internal static object _locker = new object();

    2. Use lock construction inside your plugin:

    //do your stuff here

    3. Register your assembly outside isolation.

    In case you use OnLine it would be much more complicated and you will have to find own way implementing this.

    Dynamics CRM MVP
    My blog

    Wednesday, August 5, 2015 11:35 AM
  • Hello Purva,

    I suggest you to create a plugin that will increment the counter field on the Retrieve Message of your configuration entity.
    To avoid false incrementation when only displaying this record from your browser, ensure that your are in a process by checking to context Depth (must be > 1).

    Wednesday, August 5, 2015 2:54 PM
  • Hello Purva,

    Why do we need to check Context Depth? I am using CRM online and have implemented autonumber...used locking too... but still sometimes duplicate are getting generated?

    Any recommendations on how to resolved this?



    Thanks & Regards, Sumeet Ballani Senior Consultant Off: 91 22 40622618 | Cell: 91 9004406970 | Skype: sumeet.ballani sballani@iotap.com | www.iotap.com http://in.linkedin.com/in/sumeetballani

    Tuesday, August 23, 2016 2:20 PM