Working with Primitive Types

If you want to have field that can contain a restricted set of values, but the set of values is too big for an enumerated type, you can use a Primitive Type. For example, if you need to store a Part Number in a field, this field will probably have a restricted format, such as PN-123456. If all Part Numbers have a fixed format like this, set up a User-defined Type to hold the Part Number, and restrict the type so that it only holds strings that start with PN- and are followed by six digits.

To do this, select the Primitive Type from the Elements section of the Palette. Having created one of these, you can name it. For our example, call it PartNumber. In the Advanced Properties sheet, you can define restrictions that are imposed on the field, such as numeric ranges for numeric fields and patterns for text fields. The patterns are specified using regular expressions. For our example, use:

PN-\d{6}

Which means PN- followed by 6 digits (\d is the code for a digit and {6} means six of the previous entity).

Set a class attribute to contain a PartNumbertype attribute as shown above. In scripts and forms, you can only assign values to the partNum attribute that matched the pattern PN-\d{6}.

Attributes of Primitive Types can be assigned in the same way as the BOM Native Type on which they are based, so, using the above example, the partNum field can be assigned using:

order.orderline.partNum = "PN-123456";

If a script is written with an invalid format value, as shown in the example below:

order.orderline.partNum = "ROB-123456";

the script editor will not detect this as an error, since it does not check that Strings have the correct content. Instead, this will cause a runtime validation exception when the Task that contains the script completes.