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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Custom number sequence based on Sales ID

(0) ShareShare
ReportReport
Posted on by 45

Hi,

Can you please provide examples on how can I use current Sales Id in my purchase order number sequence by code? The purchAutoCreate_sales class creates the PO number from the sales order when using direct delivery. 

I want to keep this kind of PO number sequence format like this: SO-<SalesID>-01 This is not only for identification but other purposes as well. That's why the PO number must be customized in this scenario. Is it something possible using the loadModule in NumberSeqModuleSalesOrder?

Thank You.

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    299,327 Super User 2025 Season 2 on at
    RE: Custom number sequence based on Sales ID

    Hi Pam,

    Not sure if it is possible, but anyway, there is a reference between the PO and SO on another field. Isn't this sufficient?

    If you need to customize this, then it is in fact not a sequence number which can be handled by the number sequence framework and you need to create a manual number during the copy process.

  • pam86 Profile Picture
    45 on at
    RE: Custom number sequence based on Sales ID

    The reference field is not enough as per the requirement.

    So as per your suggestion, it wont be possible by generating a number sequence using the loadModule method. I can just create a number sequence on the go using my code and assign it to the PO by interferring the PurchAutoCreate_Sales class?

  • André Arnaud de Calavon Profile Picture
    299,327 Super User 2025 Season 2 on at
    RE: Custom number sequence based on Sales ID

    Hi Pam,

    If this is the class used for creating the PO from the SO, then yes, you can hook in and extend this class.

  • pam86 Profile Picture
    45 on at
    RE: Custom number sequence based on Sales ID

    I am able to extend this class using COC. Two classes need to be extended PurchAutoCreate_Sales and PurchAutoCreate. The first/derived class calls the second/base class using super() to generate the PO number.

    I am providing more insight into my logic:

    First-class extension:

    [ExtensionOf(classstr(PurchAutoCreate_Sales))]
    final class PurchAutoCreate_Sales_Extension
    {
        public void setPurchTable()
        {
            myPurchId = salesTable.salesid;
    
            if (tradeLineDlvType == TradeLineDlvType::DropShip)
            {
                myDeliveryType = TradeLineDlvType::DropShip;
            }
    
            next setPurchTable();
        }
    
    }

    Base class extension:

    [ExtensionOf(classstr(PurchAutoCreate))]
    Final class PurchAutoCreate_Extension
    {
        public PurchId              myPurchId;
        public TradeLineDlvType     myDeliveryType;
        
    
        protected NumberSeq retrievePurchaseOrderNumberSequence()
        {
            next retrievePurchaseOrderNumberSequence();
            return this.ReturnValue();
        }
        
        public NumberSeq ReturnValue()
        {
            PurchId                 purchId;
            TradeLineDlvType        deliveryType;
            NumberSeq               abc;
            NumberSequenceTable     numtable;
            PurchAutoCreate_Sales   PurchAutoCreate_Sales;
    
            
            purchId = myPurchId;
            deliveryType = myDeliveryType;
    
            if (deliveryType == TradeLineDlvType::DropShip)
            {
                abc = NumberSeq:: //Dont know which method should be used here
                abc.used();
            }
            else
            {
                abc = this.retrievePurchaseOrderNumberSequence();
            }
            return abc;
        }
    
    }

    The base Class method which generates the PO number (out of the box):

     public void setPurchTable()
        {
            NumberSeq       num;
            PurchId         tmpPurchId;
            // 
            PurchTable_W    purchTable_W;
            // 
    
            if (!vendTable)
            {
                throw error("@SYS23020");
            }
    
            purchTable.clear();
            purchTable.initValue(this.purchType());
    
            num = this.retrievePurchaseOrderNumberSequence();
    
            tmpPurchId = num.num();

    The tmpPurchId in the base class is str. If I am not using the Number Sequence platform then how can I assign/return string value (my customized number) to the tmpPurchId? 

  • Suggested answer
    Vishal Dhavgaye Profile Picture
    405 on at
    RE: Custom number sequence based on Sales ID

    Hi Pam86,

    Few things you have to do to complete your customization here,

    1. You cant mess up with current purchase order number sequence so you will have to create new number sequence for <salesId>-XX format. 

    Please refer following link to create new custom number number sequence. Max length for purchase order string is '20' so you have to make sure you create new number sequence with string size 20.

    https://community.dynamics.com/365/financeandoperations/b/dynamics365foaxhub/posts/create-number-sequence-in-d365

    https://wingsraamax.blogspot.com/2019/04/creating-new-number-sequence-in-d365.html

    2. Once your number sequence in place, you can call NumSeq by following code.

    abc = NumberSeq::newGetNum(NumberSeqReference::findReference(extendedTypeNum('YourNewEDT')));

  • pam86 Profile Picture
    45 on at
    RE: Custom number sequence based on Sales ID

    Even if I follow all these steps it won't allow me to contain SO number inside PO number. 

    This will basically generate another number sequence that I can use using my code. What I really want it to use the current SO number sequence in my PO number sequence when its direct delivery. 

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Custom number sequence based on Sales ID

    One hint: when you create extension classes, and add new methods to them, please remember to use your own prefix in the name. Otherwise you risk having conflicts when installing future MS updates or ISV solutions.

    Let me refactor your code a bit, removing unnecessary duplicate logic, and simplify it.

    I didn't test it but perhaps you get the idea? The only thing that I'm doing is to use the Sales id number sequence instead of Purchase id number sequence, if certain condition is met.

    [ExtensionOf(classstr(PurchAutoCreate))]
    Final class MyPurchAutoCreate_Extension
    {
        protected NumberSeq retrievePurchaseOrderNumberSequence()
        {
            NumberSeq ret = next retrievePurchaseOrderNumberSequence();
            
            if (tradeLineDlvType == TradeLineDlvType::DropShip)
            {
                ret = NumberSeq::newGetNum(SalesParameters::numRefSalesId);
            }
            
            return ret;
        }
    
    }

  • pam86 Profile Picture
    45 on at
    RE: Custom number sequence based on Sales ID

    Thank you for your feedback Nikolaos. I will keep that in mind.

    Sorry, I think I did not explain my requirement in the last post properly. Based on your code, it will simply use and generate the SO number sequence instead of using the PO number sequence. My requirement is if I have created a SO with sales id 000786 and if I use direct delivery on the sales line then it should use that sales id 000786 plus increment or sales line number. For example, in this case, my PO number should look like 000786-01.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Custom number sequence based on Sales ID

    Ok so you don't want to use number sequence at all.

    You can use Chain of Command in the "setPurchTable" method of PurchAutoCreate, and replace PurchId with any value after calling next. So then you just need to be able to read the Sales id from this place in the process.

  • pam86 Profile Picture
    45 on at
    RE: Custom number sequence based on Sales ID

    That's what I have tried in my first attempt before extending retrievePurchOrderNumberSequence method. But I did not get any success in that attempt. Using CoC, how can I interfere to overwrite the purchId? If I use my logic after calling next setPurchTable(), at that point, the purchId will be already set!! Do you think it iss possible/safe to overwrite the purchId.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,122

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 918 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 646 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans