Auto Number solution where two entities need to reference the same next number RRS feed

  • Question

  • 1. What is the efficient way to create a Auto number solution where two entities need to increment the same next number.

    2. I also need a next number for a single entity.

    I am having hard time figuring which fields I need for the Setup entity which will maintain the next number for a combination of entities or a single entity.


    Saturday, December 7, 2013 4:09 AM

All replies

  • I've been though this  and on my experience there are two ways

    Using mutex:


    I'm sure that works well on a CRM set without load balancing (only one front end for one sql server)

    I have my doubts when you are on a load balance server. I've seen people using mutex on load balanced CRM and getting duplicates. there is a long way from reading the current number, assign to the record and than auto increment. the best way is to do it on a database transaction.

    Now are you on crm 4.0 or 2011

    for 2011 you can take advantage of the transactions. just create an entity to store the auto number and than you can increment it and read from it using a plugin. But you must do the operation within the transaction stage

    this is a good example:


    note the part saying "Next we wrote a plugin that hooked into the Pre-Create event synchronously,
     check the target"

    this is because the pre event is within the transaction

    Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage are executed within the database transaction.


    If you are on 4.0, you won't have that luxury. You can create a separated database and use a stored procedure (don't create a stored procedure on the CRM database)

    I Hope I could help. If I have answered please mark as 'Answer'. If was just helpful, please vote. Thanks and happy coding! Bruno Lucas, http://dynamicday.wordpress.com/

    • Proposed as answer by SravaniRN459 Tuesday, December 10, 2013 5:31 AM
    Saturday, December 7, 2013 8:51 PM
  • Hi ,

    To maintain the Sequence number for system or custom entity , please click this link http://srmscrm.wordpress.com/2012/10/30/sequence-numberauto-number-for-custom-entity-in-ms-crm-2011/

    Hope this may help you.

    Warm Regards, Suresh Kumar D

    Tuesday, December 10, 2013 4:00 AM