web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Duplicate Sequence Number in CRM 2013

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am facing a weird issue in Opportunity entity.
In very random cases,when using save as functionality for product,duplicate sequence number is being assigned to the product.
My logic for assigning the sequence number is in a plugin.
I am not able to reproduce except i found that it is being generated through save as functionality.

Any help would be appreciated.

Thanks in Advance.

*This post is locked for comments

I have the same question (0)
  • shivaram Profile Picture
    3,315 on at

    Hi Ripal,

    May I know how you are retrieving Max number?

    If you got max number then add number and assign it. Please tell me how you are getting max number.

    Thanks.

  • Wayne Walton Profile Picture
    13,730 on at

    Are you properly using SQL locking to make sure that the plugin isn't firing twice and getting the same number before it's incremented?  CRM plugins support the method, and it will guarantee your plugin gets a unique number.

  • Suggested answer
    razdynamics Profile Picture
    17,308 User Group Leader on at

    Hi Ripal, Agree with Wayne that many custom Autonumber solutions do not handle concurrency very well. However I am happy to share my solution with you, or you can download from Celedon Partners or ADXStudio productivity Pack.

  • Community Member Profile Picture
    on at

    Hi All,

    Thanks for your answers.

    I am not using any auto number generation logic.

    I am just simply retrieving the max sequence number through a query and then according to the method of generation of the Product,I am incrementing and assigning sequence number.

  • Wayne Walton Profile Picture
    13,730 on at

    Yup, that will definitely give you duplicates, as you can retrieve the same max at the same time if you don't have a read lock on the field while it's getting updated.

  • Suggested answer
    shivaram Profile Picture
    3,315 on at

    Hi Ripal,

    Can you try following code?

    Actually I created two records with same sequence number then I created one more record with next sequence. So it will take sequence num and added 1 to Max number. There is no duplicate sequence number.

    Try following code once

    using (var xrm = new XrmServiceContext(service))
    {
    Account a = new Account();
    var seqnum = xrm.AccountSet.ToList();
    long? Sequence = 1000000;
    if (seqnum.Count > 0)
    {

    Sequence = Convert.ToInt32(seqnum.Max(r => r.new_SequenceNumber) + 1);
    if (Sequence < 1000000)
    Sequence = 1000000;
    service.Create(new Account
    {
    new_Name= "using Online",
    new_SequenceNumber= (int)Sequence
    });
    }
    }

     

    Hope it helps you

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans