ANS-0398 · INVENTORY & ITEM MANAGEMENT
How to Automatically Generate UPC Codes for Items in NetSuite
Implement a custom NetSuite workflow to automate UPC code generation, ensuring uniqueness and adherence to specific validation logic.
Short answer
To automatically generate UPC codes in NetSuite, a custom "After Submit" workflow can be configured. This workflow leverages the item's internal ID for uniqueness, concatenates a predefined 11-digit sequence, and then calculates and appends the 12th validation digit using specific NetSuite formula functions.
Scenario
Organizations often require automated generation of Universal Product Codes (UPCs) for their inventory items within NetSuite. While standard NetSuite features exist for automated numbering, specific business rules or complex validation logic for UPCs may necessitate a tailored solution to ensure unique and correctly formatted codes are assigned upon item creation.
Solution
While NetSuite offers solutions like the 'Auto Assign UPC SuiteApp' and 'Advanced Numbering' features for automated item numbering, specific business requirements for UPC generation, particularly those involving custom calculation logic, may necessitate a workflow-based approach. This solution outlines how to implement a custom workflow to automatically generate UPC codes for items, leveraging NetSuite's internal ID for uniqueness and applying a specific validation formula.
A workflow should be created that triggers "After Submit". This trigger is crucial because the item's internal ID ('id') is not set until after the record has been submitted, and this ID is essential for ensuring uniqueness in the generated UPC. The workflow will then execute a series of actions:
Define a Custom Workflow Field:
Create a custom workflow free form text field, for example,
{custworkflow_wf_next_upc_number}. This field will initially contain the first 11 digits of the UPC code sequence (e.g., "12345678901"), which must be provided by the customer and set as its default value. This custom field's value is then combined with the item's internal ID ('id') to create a unique 11-digit base for the UPC.Calculate the 12th Digit:
A second workflow action computes the 12th (validation) digit using the following formula. This formula calculates the check digit based on the preceding 11 digits:n
10 - MOD(SUBSTR({custworkflow_wf_next_upc_number}, 2, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 4, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 6, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 8, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 10, 1)+(SUBSTR({custworkflow_wf_next_upc_number}, 1, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 3, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 5, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 7, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 9, 1)+SUBSTR({custworkflow_wf_next_upc_number}, 11, 1)) * 3,10)nn
Finalize and Append the UPC:
A final workflow action checks the calculated 12th digit. If the result of the validation number calculation is '10', it should be switched to '0' to maintain the correct single-digit format. The final 12-digit UPC is then constructed by appending this last digit to the initial 11-digit sequence.n
CASE WHEN {custitem_upc_validation_number} = '10' THEN CONCAT({custworkflow_wf_next_upc_number},'0') ELSE CONCAT({custworkflow_wf_next_upc_number},{custitem_upc_validation_number}) ENDThis final UPC code is then assigned to the appropriate item field.
Expert NetSuite Support
Need help with this NetSuite issue?
Inventory & Item Management consulting and configuration support
