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 Microsoft Employee

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

  • Suggested answer
    shivaram Profile Picture
    shivaram 3,315 on at
    RE: Duplicate Sequence Number in CRM 2013

    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.

  • Wayne Walton Profile Picture
    Wayne Walton 13,728 on at
    RE: Duplicate Sequence Number in CRM 2013

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Duplicate Sequence Number in CRM 2013

    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.

  • Suggested answer
    razdynamics Profile Picture
    razdynamics 17,304 User Group Leader on at
    RE: Duplicate Sequence Number in CRM 2013

    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.

  • Wayne Walton Profile Picture
    Wayne Walton 13,728 on at
    RE: Duplicate Sequence Number in CRM 2013

    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.

  • shivaram Profile Picture
    shivaram 3,315 on at
    RE: Duplicate Sequence Number in CRM 2013

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans