GTIN Assignment Rule

You can automatically generate GTINs and create GTIN relationships using the assignment item rule.

When creating an assignment rule, you must select GTIN as the return type. You can leverage the existing capabilities of item rules such as call a web service, auto sequence function, fetch values from custom objects or item attributes, and so on, to generate the GTIN. Then, the assignment rule automatically creates the GTIN relationships.

Create and Assign GTIN Rule

To generate GTIN and create GTIN relationships automatically, use the assignGTIN function in the Return Value field.

The syntax is:

assignGTIN (<GTIN String/Expression>, <UOM Code>, <Party Type>, <Registry ID>)

You can use a rule function that generates a GTIN as the first argument. Pass the UOM code as the second argument that will be used as the GTIN UOM. Party type and registry ID are optional arguments (either both must be specified or both must be blank). You can pass party type and registry ID to create party GTIN relationships. This GTIN expression can be a concatenation of multiple values. You can create multiple GTIN assignment rules to create more than one GTIN relationship.

If the attribute is updated, the rule won't delete a relationship, or won't update an existing relationship. It attempts to create a new relationship. If a new relationship with the given values is allowed, the creation transaction will be successful.

If there is a relationship existing with the given values, a new GTIN relationship can't be created.

If an attribute is changed to null or a row is deleted in the multirow attribute, the rule fails. A message is displayed indicating that there is already a GTIN relationship with the same specification. Hence, a new GTIN relationship can't be created.

Examples:
  • Use constants: assignGTIN ("00002584109872", "EA", "Manufacturer", "CD1234")
    • First argument must be a 14-digit string.
    • Second argument must accept both UOM code and lookup meaning.
    • Third argument (party type) must be a customer, manufacturer, or supplier.
    • Fourth argument must be the registry ID of a customer, manufacturer, or supplier.
  • Pass item attributes: main, basic, or extended flexfields and/or expressions:

    assignGTIN([Item].[Item Basic].[Item], [Item].[Main].[Primary Unit of Measure])

    assignGTIN([Item].[AG1].[A1] + [Item].[AG1].[A2] , [Item].[AG1].[U_Code], [Item].[AG1].[P_TYPE], [Item].[AG1].[R_ID])

    assignGTIN(InvokeWebservice("GTIN_Prefix", "Fetch", [Item].[Item Basic].(Item Class]) + auto_sequence ("Prod_Seq", 100000, 1) + gtinCheckDigit ( [Item].[GTIN_Details].[UPC]) , [Item].[Main].[Primary Unit of Measure])

  • Create additional GTIN relationship for the same item:

    assignGTIN("20002584109872", "5Pack")

You can generate and assign multiple GTINs to an item using a single rule. For example, assign internal GTIN, party GTINs, and additional pack GTINs to an item using a single rule. Use the existing rule functions to generate GTINs and then use these functions inside the assignGTIN function. You can add multiple assignGTIN functions in the return value field of a GTIN rule.

Here's an example that shows an expression that can be added to the return value field of GTIN assignment rule.
assignGTIN(getCustomObjectValue["GTIN_Prefix","Prefix","Level"+[ITEM].[Info].[L1],[Item].[Codes].[UPC],"Ea"),assignGTIN(invokeWebservice("GTIN_Core","Fetch") "Ea","Supplier","CO1234")
You can use the getItemGTIN function in rules to get a GTIN from existing item GTIN relationships. Here are a few examples:
  • Get the GTIN for which the GTIN UOM is same as the Primary UOM of the item:

    getItemGTIN([GTIN].[GTIN Main].[UOM] == [Item].[Main].[Primary Unit of Measure])

  • Get the context item's GTIN for which GTIN UOM and Primary UOM match and the Party Name is XYZ Ltd.:

    getItemGTIN( [GTIN].[GTIN Main].[UOM] == [Item].[Main].[Primary Unit of Measure] AND [GTIN].[GTIN Main].[Party Name] == "XYZ Ltd" )

  • Get the context item's GTIN whose GTIN UOM is 5Pack:

    getItemGTIN( [GTIN].[GTIN Main].[UOM] == "5Pack")

You can use this expression in a GTIN assignment rule to create additional GTIN relationships. Also, you can:
  • Derive key parts from the GTIN obtained from existing relationships using the getItemGTIN function and then you can use these parts for generating additional GTINs.
  • Use this GTIN for validation purposes.

The following example invokes an API, sends context item''s Pack-GTIN and another value "10Pack". Based on these two input parameters, the external API can compute a GTIN and return the GTIN number; Rule creates a GTIN relationship with the returned GTIN number and with GTIN UOM "10Pack".

assignGTIN(InvokeWebservice("GTIN_Compute", getItemGTIN( [GTIN].[GTIN Main].[UOM] == [Item].[Main].[Primary Unit of Measure]),"10Pack" ), "10Pack")

Calculate Check Digit for GTINs

You can calculate the check digit for GTIN 8, GTIN 12, GTIN 13, or GTIN 14 using the gtinCheckdigit( ) item rule function.

The syntax of the function is:

gtinCheckdigit( ).

You can pass a 7, 11, 12, or 13-digit number to calculate the check digit for GTIN 8, GTIN 12, GTIN 13, or GTIN 14 respectively. The function will perform a mod 10 check digit calculation and return the check digit.

You can also pass an expression in the GTIN check digit function. This expression must return a 7, 11, 12, or 13-digit number.

Using rules, you can pass check digit and append the check digit with the other digits. For example:

assignGTIN([Item].[AG1].[Indicator_Digit] + [Item].[AG1].[Company_Prefix] + [Item].[AG1].[Item_Ref] + gtinCheckdigit ([Item].[AG1].[Indicator_Digit] + [Item].[AG1].[Company_Prefix] + [Item].[AG1].[Item_Ref]) , "Each")

Alternatively, you can create rules:

Rule 1: Attribute G-13 = [Item].[AG1].[Indicator_Digit] + [Item].[AG1].[Company_Prefix] + [Item].[AG1].[Item_Ref]

Rule 2: assignGTIN([Item].[AG1].[G-13] + gtinCheckdigit([Item].[AG1].[G-13]) , "Ea")

The preceding examples also demonstrate how you can use the check digit function in GTIN assignment rules.