Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested answer

API Endpoint to retrieve next value in Number Sequence

(2) ShareShare
ReportReport
Posted on by 33
Hi All,
 
I have got a FinOps and Sales instance set up and working. I just have 1 problem that Auto Generated numbers from Sales and FinOps do not match.
 
For example, a Sales Order created in Sales has a number that looks like "ORD-01103......" and an Order created in FinOps has a number that looks like "SO0012345".
 
I want sales to be able to not generate a number it self, and just let FinOps do it with the Number Sequence.
 
 
From what I have read, the best way to do it is by creating a Data Entity within FinOps and getting it to retrieve the next available ID and return that in an API call (probably made by power automate with a trigger of "when a row is added").
 
Can anyone confirm whether there is a better way to do this? and if not, help me write the code for the Data Entity as I am only fairly new to this.
 
 
Thanks,
Jacob
  • JB-27010340-0 Profile Picture
    33 on at
    API Endpoint to retrieve next value in Number Sequence
     
     
    Could you please step me through all of that, from start to finish?
     
    Sorry, I am only new to this.
     
     
    Thanks,
    Jacob
  • Suggested answer
    Saif Ali Sabri Profile Picture
    1,997 Super User 2025 Season 1 on at
    API Endpoint to retrieve next value in Number Sequence

    Microsoft Dynamics 365 Finance and Operations uses Number Sequences to generate unique identifiers for entities like Sales Orders. The goal is to expose an API endpoint that retrieves the next available number for a specific Number Sequence (e.g., Sales Orders) and return it to external systems (such as Dynamics 365 Sales via Power Automate).

    1. Create a Custom Data Entity to Expose the Next Available Number

    You need to create a Data Entity that will call the NumberSeq framework to fetch the next number.

    Step 1: Create a Custom Query

    1. Open Visual Studio (with Finance and Operations SDK installed).
    2. In Application Explorer, navigate to AOT > Queries.
    3. Right-click Queries, select New Query, and name it: CustomNumberSequenceQuery.
    4. Drag the NumberSeqReference table to the Data Sources section of the query.
    5. Save and close the query.

    Step 2: Create a Custom Data Entity

    1. In Application Explorer, right-click Data Entities > Add New Data Entity.
    2. Name it: CustomNumberSequenceEntity.
    3. In the Primary Data Source, select the CustomNumberSequenceQuery.
    4. Set Public Collection Name and Public Entity Name as CustomNumberSequenceEntity.
    5. Enable Is Public = Yes (to allow OData access).

    Step 3: Add a Custom Method to Get the Next Number

    Modify the entity’s logic to call the Number Sequence framework.

    csharp
    public static str GetNextNumberSequence(str numberSeqCode)
    {
    NumberSeq numSeq;
    NumberSeqScope scope;
    str nextNumber;

    ttsBegin;


    // Get the number sequence
    scope = NumberSeqScopeFactory::createDataAreaScope();
    numSeq = NumberSeq::newGetNumFromCode(numberSeqCode, scope);


    if (numSeq)
    {
    nextNumber = numSeq.num();
    }

    ttsCommit;


    return nextNumber;
    }
     

    Step 4: Expose the Method as an OData API

    Modify the Data Entity to expose the method.

    csharp
    [SysODataActionAttribute("GetNextNumberSequence", false)]
    public static str GetNextNumberSequence(str numberSeqCode)
    {

    return GetNextNumberSequence(numberSeqCode);
    }
     

    • SysODataActionAttribute exposes the method as an OData endpoint.
    • numberSeqCode should be the code for the number sequence used in Sales Orders.


    •  

    2. Deploy and Test the API

    Step 1: Build and Deploy

    1. Build the solution.
    2. Synchronize the database.
    3. Deploy the package to the FinOps environment.

    Step 2: Test the API

    1. Use Postman or a browser to test the OData service.
    2. Format of the API endpoint:
    ruby
    https://your-finops-instance.cloudax.dynamics.com/data/CustomNumberSequenceEntity/Microsoft.Dynamics.DataEntities.GetNextNumberSequence
    1. Send a POST request with the following JSON payload:
    json
    {
    "numberSeqCode": "SalesOrderNumber"
    }
     
    1. The response should return the next available Sales Order number.

    2.  

    3. Connect FinOps API with Power Automate

    To ensure Dynamics 365 Sales retrieves the next number from FinOps:

    1. Trigger: "When a row is added" in Dataverse (for a new Sales Order).
    2. HTTP Action: Call the FinOps API using a POST request.
    3. Update Sales Order: Assign the retrieved number to the Sales Order.
     

    Final Outcome

    • When a new Sales Order is created in Dataverse, Power Automate triggers the API call.
    • FinOps generates the next number sequence and returns it.
    • Sales Order in Dataverse is updated with the same number as in FinOps.

    •  

    Alternative Approach

    Instead of exposing a new Data Entity, you could:

    • Use Dual-Write to sync Sales Order numbers.
    • Call Custom Business Events in FinOps to trigger number sequence retrieval.

    However, for direct API-based integration, the custom OData API approach is the most efficient.

     

    Conclusion

    This solution ensures that Sales Orders in Dynamics 365 Sales and FinOps use the same Number Sequence, preventing mismatched IDs.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,459 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,066 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans