Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 13977

How to reset Auto-numbering in Dynamics CRM Online

$
0
0

In past I have shown how to reset auto-numbering un-supported way. Today I am going to discuss how we can reset auto-numbering by Microsoft supported way.

Number greyed-out so it can't be changed through UI. But we can write a small console application to update it using SDK.



Following code can be used to update the number. In this example I am updating CurrentKbNumber but we can also update CurrentCaseNumber, CurrentContractNumber, CurrentQuoteNumber, CurrentOrderNumber and CurrentInvoiceNumber. However we don't need to worry about prefix and they can be updated through UI.

    // QueryExpression to Retrieve Organization
    QueryExpression qe = newQueryExpression("organization")
    {
        ColumnSet = newColumnSet(newstring[] {"organizationid", "name", "currentkbnumber"})
    };
    EntityCollection orgs = service.RetrieveMultiple(qe);

    if (orgs != null&& orgs.Entities.Count > 0)
    {
        var org = orgs[0];
        var organizationId = (Guid)org["organizationid"];

        // Creating a new Object to update. Set the CurrentKbNumber to your desired number
        OrganizationorganizationToUpdate = newOrganization { CurrentKbNumber = 100000, Id = organizationId};
        service.Update(organizationToUpdate);
    }    

Once updated, please Got to Settings > Administration > Auto-numbering to verify.

Happy Coding

P. S. Hayer


Viewing all articles
Browse latest Browse all 13977

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>