{"id":32234,"date":"2026-06-29T12:31:50","date_gmt":"2026-06-29T12:31:50","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/sagex3\/?p=32234"},"modified":"2026-06-29T14:00:11","modified_gmt":"2026-06-29T14:00:11","slug":"creating-a-custom-sequence-number-in-sage-x3-using-a-function","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/sagex3\/2026\/06\/29\/creating-a-custom-sequence-number-in-sage-x3-using-a-function\/","title":{"rendered":"Creating a Custom Sequence Number in Sage X3 Using a Function"},"content":{"rendered":"\n<p>In many business scenarios, the standard sequence numbering provided by <a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/development-services\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.greytrix.com\/sage-x3-erp\/development-services\/\" rel=\"noreferrer noopener\">Sage X3<\/a> may not fully satisfy statutory, operational, or reporting requirements. Organizations often require document entry numbers that contain additional business-specific information such as:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Fiscal Year<\/li>\n\n\n\n<li>State Code<\/li>\n\n\n\n<li>Unit Identifier<\/li>\n\n\n\n<li>Location Code<\/li>\n<\/ol>\n\n\n\n<p>This article explains how to create a custom sequence number in Sage X3 by using a user-defined function within the sequence number formula. The solution leverages a custom script that dynamically fetches the required values and returns them to the sequence number formula.<\/p>\n\n\n\n<p>The client required transaction entry numbers to be generated in the following format:<br>\u2022 SITE STATE CODE<br>\u2022 FISCAL YEAR<br>\u2022 CONSTANT<br>\u2022 SEQUENCE<\/p>\n\n\n\n<p>Example: 2727IV00137<br>Where<br>The State Code represents the GST registration state of the site (27),<br>Fiscal Year represents the financial year associated with the transaction (27),<br>Constant represents as user specific data (IV),<br>Sequence Number is the standard running counter maintained by Sage X3 (00137).<\/p>\n\n\n\n<p>The solution needed to dynamically derive the State Code and Fiscal Year during transaction creation without requiring manual intervention is as follows:<\/p>\n\n\n\n<p><strong>Step 1: Create a reusable custom function.<\/strong><\/p>\n\n\n\n<p>A custom Sage X3 script was developed containing a function capable of returning different values based on the parameter passed in function .The function accepts a parameter indicating the information required.<\/p>\n\n\n\n<p>In Sage X3 system, the Sales Invoice screen and the Customer BP Invoice screen are configured to use the same sequence number (common numbering series). To achieve this, the standard sequence generation function is called from the screen script and are dynamically passing the required parameters (such as Site, Date, etc.) directly from the current screen context.<\/p>\n\n\n\n<p><strong>Step 1a.<\/strong> Derive the State Code dynamically from the transaction site configuration.<\/p>\n\n\n\n<p>Retrieval flow:<br>Transaction Site \u2192 Site Master \u2192 Address Information \u2192 State Master GST number \u2192 State Code from GST number.<\/p>\n\n\n\n<p><strong>New Stuff:<\/strong> <a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2026\/06\/29\/understanding-automatic-closure-of-rejected-pos-in-sage-x3\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2026\/06\/29\/understanding-automatic-closure-of-rejected-pos-in-sage-x3\/\" rel=\"noreferrer noopener\">Understanding Automatic Closure of Rejected POs in Sage X3.<\/a><\/p>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/06\/Site-Master.png\" target=\"_blank\" rel=\"noreferrer \nnoopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; \nalign: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/06\/Site-Master.png\" alt=\"Site Master\"><\/a><\/center> \n<font size=\"2\"><center>Site Master<\/center><\/font>\n\n\n\n<p>Example values returned: 27 (MH), 29 (KA), 33 (TN), 24 (GJ)<br>This ensures that the generated entry number always reflects the correct state associated with the transaction.<\/p>\n\n\n\n<p><strong>Step 1b. <\/strong>Derive the Fiscal Year based on the accounting date.<br>Retrieval flow:<br>Transaction Accounting Date \u2192 Fiscal year master \u2192 Fiscal year \u2192 Description<\/p>\n\n\n\n<center><a href=\"hhttps:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/06\/Fiscal-year-Master-1024x278.png\" target=\"_blank\" rel=\"noreferrer \nnoopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; \nalign: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/06\/Fiscal-year-Master-1024x278.png\" alt=\"Fiscal year Master\"><\/a><\/center> \n<font size=\"2\"><center>Fiscal year Master<\/center><\/font>\n\n\n\n<p>Example:<br>Accounting Date = 15-Apr-2026<br>Returned Fiscal Year desc = 27<\/p>\n\n\n\n<p><strong>Step 2: Sequence number configuration<\/strong><\/p>\n\n\n\n<p>Navigate to: All \u2192 Setup \u2192 General Parameters \u2192 Sequence number definition \u2192 Structure.<\/p>\n\n\n\n<p>Assign the function in the formula as shown in the below figure in the form of structure required.<\/p>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/06\/Sequence-structure-1024x235.png\" target=\"_blank\" rel=\"noreferrer \nnoopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; \nalign: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-content\/uploads\/2026\/06\/Sequence-structure-1024x235.png\" alt=\"Sequence structure\"><\/a><\/center> \n<font size=\"2\"><center>Sequence structure<\/center><\/font>\n\n\n\n<p><strong>Note:<br><\/strong>In our case we have assigned the Site and Fiscal year value as zero as need to reset the sequence based on site and fiscal year. Once configured, Sage X3 automatically invokes the custom function during document creation.<\/p>\n\n\n\n<p><strong>Conclusion:<\/strong><br>Sage X3 provides significant flexibility in sequence number generation through formula-based numbering. By incorporating a custom user-defined function into the sequence formula, organizations can generate intelligent document numbers that include business-relevant information such as State Code and Fiscal Year. This approach delivers enhanced traceability, improved compliance, and a scalable framework for future numbering requirements while maintaining the integrity of Sage X3&#8217;s standard sequence management functionality.<\/p>\n\n\n\n<p>Additionally, the same function can be reused across multiple Sage X3 transaction types including:<br>\u2022 Sales Invoices<br>\u2022 Purchase Invoices<br>\u2022 Journal Entries<br>\u2022 Stock Transactions<br>\u2022 Payment Transactions<\/p>\n\n\n\n<p>Any future changes to Fiscal Year or State Code determination can be managed within a single function rather than modifying multiple sequence definitions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In many business scenarios, the standard sequence numbering provided by Sage X3 may not fully satisfy statutory, operational, or reporting requirements. Organizations often require document entry numbers that contain additional business-specific information such as: This article explains how to create a custom sequence number in Sage X3 by using a user-defined function within the sequence\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/sagex3\/2026\/06\/29\/creating-a-custom-sequence-number-in-sage-x3-using-a-function\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,13],"tags":[4574,2747,4575,2044,2289],"class_list":["post-32234","post","type-post","status-publish","format-standard","hentry","category-sage-erp-x3","category-integration","tag-custom-function","tag-fiscal-year","tag-master","tag-sequence","tag-transactions"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/32234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/comments?post=32234"}],"version-history":[{"count":11,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/32234\/revisions"}],"predecessor-version":[{"id":32259,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/posts\/32234\/revisions\/32259"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/media?parent=32234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/categories?post=32234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/sagex3\/wp-json\/wp\/v2\/tags?post=32234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}