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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Number sequence for new item based on item group number sequence set up

(0) ShareShare
ReportReport
Posted on by 214
Hi All,

 

I want to implement item number generation based on the number sequence configured for the selected Item Group.

In standard D365 FO functionality, for Customers and Vendors, it is possible to assign a number sequence to a Customer Group or Vendor Group. When creating a new customer or vendor, if the selected group has a number sequence configured, the newly created customer or vendor account number is generated from that group's number sequence.

During my analysis:

  1. I debugged the vendor number sequence logic and observed that when a new vendor is created, if the selected Vendor Group has a number sequence assigned, the vendor account number is generated from that specific number sequence.

  2. While trying to implement similar functionality for Item creation, I noticed that the item creation form (EcoResProductCreate) is used when creating a new item, and this form does not contain any datasource.

  3. I mention the datasource because I observed that the numberSeqFormHandler() method in the Vendor form is responsible for handling number sequence generation based on the Vendor Group setup.

  4. Inside this method, the standard implementation passes VendTable as the datasource when creating the NumberSeqFormHandler instance. Therefore, when trying to replicate the same approach for item number generation, I am unable to do so because the EcoResProductCreate form does not have a datasource.

  5. In the below standard code(which is called when the vendor group or customer group is modifeid while creating new vendor or customer), the newForm() method is called from within numberSeqFormHandler(), and the datasource is passed as a parameter. Since EcoResProductCreate has no datasource, I am facing difficulties implementing the same pattern for item number generation.

Could you please advise whether there is another recommended approach to achieve this requirement? Are there any standard classes or methods that can be used instead of numberSeqFormHandler() for this scenario? Alternatively, would it be appropriate to add an InventTable datasource to the EcoResProductCreate form to support this functionality?


1.NumberSeqFormHandler numberSeqFormHandler()
{
    VendTable vendor = VendTable_ds.cursor();
    VendGroup vendGroup = VendGroup::find(vendor.VendGroup);
    if (VendGroup.VendAccountNumSeq)
    {
        if (!numberSeqFormHandler || numberSeqFormHandler.parmNumberSequenceId() != VendGroup.VendAccountNumSeq)
        {
            numberSeqFormHandler = NumberSeqFormHandler::newForm(VendGroup.VendAccountNumSeq,
                                                            element,
                                                            vendTable_DS,
                                                            fieldNum(VendTable, AccountNum)
                                                        );
        }
    }
    else 
    {
        if (!numberSeqFormHandler || numberSeqFormHandler.parmNumberSequenceId() != VendParameters::numRefVendAccount().NumberSequenceId)
        {
            numberSeqFormHandler = NumberSeqFormHandler::newForm(VendParameters::numRefVendAccount().NumberSequenceId,
                                                            element,
                                                            vendTable_DS,
                                                            fieldNum(VendTable, AccountNum)
                                                        );
        }
    }
    
    return numberSeqFormHandler;
}
 
 
2.static NumberSeqFormHandler newForm(RefRecId                 _numberSequenceId,
                                    ObjectRun                _callerForm,
                                    FormDataSource          _formDataSource,
                                    FieldId                 _fieldIdNum,
                                    boolean                 _dontThrowOnMissingRefSetUp = false
                                   )
{
    NumberSeqFormHandler numberSeqFormHandler;
    if (!_formDataSource || !_fieldIdNum)
        throw error(strFmt("@SYS70841",funcName()));
    numberSeqFormHandler = NumberSeqFormHandler::construct(_formDataSource);
    numberSeqFormHandler.parmNumberSequenceId(_numberSequenceId);
    numberSeqFormHandler.parmFormDataSource(_formDataSource);
    numberSeqFormHandler.parmFieldIdNum(_fieldIdNum);
    numberSeqFormHandler.parmDontThrowOnMissingRefSetUp(_dontThrowOnMissingRefSetUp);
    return numberSeqFormHandler;
}
 
3.static NumberSeqFormHandler construct(FormDataSource _formDataSource)
{
    ClassName handlerClassName;
    if (tableIdToHandlerClassName == null)
        NumberSeqFormHandler::initializeNumberSeqFormHandler();
    if (tableIdToHandlerClassName.exists(_formDataSource.table()))
    {
        handlerClassName = tableIdToHandlerClassName.lookup(_formDataSource.table());
        return DictClass::createObject(handlerClassName);
    }
    return new NumberSeqFormHandler();
}
Categories:
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,872 Most Valuable Professional on at
    In case of EcoResProductCreate form, notice numberSeqItem() method. It takes the number sequence from InventParameters::numRefItemId(), but you can extend it to work differently. If you create a CoC extension and assign a different value to numberSeqItem before calling next, your value will be used instead of the standard one.
     
    Don't forget that this change will address just this single form, while you must also address other places used to create items (such as data entities and code for releasing a product).

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 461 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2026 Season 1

#2
Subra Profile Picture

Subra 428

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans