locked
Autonumber Plugin not giving Unique Number RRS feed

  • Question

  • HI All

    1. Can we implement Mutex for Online CRM .

    2. I have Written one Autonumber Plugin on Create of Account . I have created one workflow , On Update of Contact  this workflow is creating a Account record . Now i am selecting 20 contacts record and upating them , Workflow is getting fire on the update and its creting 1 account for each contact . On Account Creation Plugin is firing and its applying the Autonumber on Account . Problem is Many account having same Autonumber Value .  I used Lock in my code and its working in Onpremise CRM but not in Online CRM .

    So please tell me what is the possiblr workaround for this .... 


    Zafar Khan

    Thursday, May 9, 2013 1:58 PM

Answers

All replies

  • Hey Zafar,

    Came across this solution for auto numbering a while ago. In the comments there are a few lines around Mutex. Should be able to get you up and working in the fashion you described.

    http://m-atif.blogspot.com.au/2011/12/auto-number-solution-for-dynamics-crm.html

    Take a look and let me know what you think!

    Thursday, May 9, 2013 5:47 PM
  • Hi Brett 

    Thanks for your reply

    I implemented Lock concept in my code . That's working perfectly in Onpremise CRM , but not working in ONline CRM . I google many blog and some where i found that Online crm runs in cloud on Multiple server , but Mutex Concept work only on single server Configuration . I will try this one more time and let you know . But can you tell me what could be the other solution for my requirement .......

    Once again thanks for your effort..

     


    Zafar Khan

    Thursday, May 9, 2013 6:18 PM
  • Hi,

    You are right - the mutex technique won't guarantee a unique number. You need to use a transaction to lock the record before getting the next number - see http://advcrm2011autonumber.codeplex.com/

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, May 9, 2013 7:59 PM
    Answerer
  • Hi,

    Try to use custom db to lock last Auto Number. 

    Thanks:)

    Friday, May 10, 2013 3:11 AM
  • Hi Zafar,

        This is what we did in one of the projects and it worked like a charm.

    1) Create a seperate entity for holding the last number.

    2) Create a pre create sync plug-in on the Account entity. In this plug-in we used lock to lock the record to avoid any other request updating the number at the same time. Incremented the number and assigned the number back to custom entity.

    3) Release the lock at the end.

    4) Remember to put the code in try/catch block and in the catch blosk release the lock else in case of failure no one can generate next numbers.

    Here is the link to simple locking mechanism we used from MSDN

    http://msdn.microsoft.com/en-us/library/c5kehkcz(v=vs.71).aspx


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Friday, May 10, 2013 3:21 AM
  • Hi Zafar,

    what I believe, mutex is not supported in sandbox. 

    So you need to use a separate entity and try with locking.

    Cheers!!!

    Friday, May 10, 2013 5:25 AM
  • A mutex can only enforce uniqueness if you only have the one Crm Server in the deployment, which is not the case for Crm Online. The only way that you can guarantee uniqueness is to control locking on a shared resource (normally a SQL database record). Crm Online does not provide direct access to any shared resources that you can lock, but what you could do is to build a web service hosted in Azure, have the web service generate unique numbers based on locking on a SQL Azure database, and call the web service from your plugin


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, May 10, 2013 7:13 AM
    Moderator
  • Hi, Please maintain autonumber in a separate custom database and write query in your plugin to get last autonumber. Only this way uniqueness can achieve and locking of last number. Note: Pass sql connection string (in plugin) from CRM custom entity to access custom db. Thanks, Please vote, if you find this post helpful.
    Friday, May 10, 2013 8:11 AM
  • Hi R_Mundra

    Thanks for ur reply ..  Are you saying i need to integrate Online CRM with Custom Database , I read on Some blog that "Crm Online will not allow you to use a direct SQL connection within a plugin (this is due to the code access security implemented by the Crm Sandbox). " . Have you tried this with online CRM . Please let me know .

    Thanks for your help .. 


    Zafar Khan

    Friday, May 10, 2013 11:30 AM
  • Hi Zafar,

    You don't need an external database since there is a 'trick' to create a read lock on the sequence entity. See http://www.crmsoftwareblog.com/2012/01/implementing-robust-microsoft-dynamics-crm-2011-auto-numbering-using-transactions/

    for more info.


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, May 10, 2013 11:52 AM
    Answerer
  • Hi Minal

    In your reply you have mentioned that you used " lock " object to lock the CRM record . I have shearched on google and what i understood is Online CRM runs on Multiple Server so Lock will not work for it . Please correct me if i am wrong . I also tried  using lock object . That is working in Onpremise but not in Online . Can you please confirm me what you suggested , that you have deplooyed in OnLine . 

    Thanks for your Effort 


    Zafar Khan

    Friday, May 10, 2013 11:56 AM
  • Hi Zafar,

        The version with lock was used for on-premise. Apologies I did not check you wanted it for online. For Online we used the combination of RandomGeneration to get unique number and check if exists in the crm instance.

    -Minal

    Friday, May 10, 2013 12:59 PM
  • Hi Scott 

    Thanks for this great post . It worked for me . CRM Transaction Update Lock , Its really Awesome to know this feature . i tested this for 250 records and its working Perfectly .

    But can you tell me if there is heavy load on CRM then What could be the Problem with this one . Because Plugin having some max no of time out . 

    Once Again thanks for your help .  


    Zafar Khan


    • Edited by Zafar.Khan Friday, May 10, 2013 3:09 PM
    Friday, May 10, 2013 3:08 PM
  • Hi Zafar,

    You're welcome!

    Performance will only be affected due to the serial nature of creating records - but this is necessary to create unique numbers. The timeout would only be a problem if you get dead lock issues - but providing you create records in the same order you should be ok.

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, May 10, 2013 8:08 PM
    Answerer