Item Rule Logical Functions and Operators
Use item rule logical functions and operators to test the validity of expressions.
Logical Operators
The logical operators available in item rules are listed below.
-
and
(logical AND) -
or
(logical OR) -
not
(logical NOT)
and
Syntax:
expression1 and expression2
You can also use the notation &&
in place of the and
operator.
The logical and
operator
implements the following truth table for expression1
and expression2
.
expression1 |
expression2 |
expression1 and expression2 |
---|---|---|
F |
F |
F |
F |
T |
F |
T |
F |
F |
T |
T |
T |
F |
null |
F |
null |
*[see note] |
null |
* The processor stops after it finds the first FALSE.
Hence there is an asymmetry between F and null
and null and F
.
or
Syntax:
expression1 or expression2
You can also use the notation ||
in place of the or
operator.
The logical or
operator
implements the following truth table for expression1
and expression2
.
expression1 |
expression2 |
expression1 or expression2 |
---|---|---|
F |
F |
F |
F |
T |
T |
T |
F |
T |
T |
T |
T |
T |
Null |
T |
null |
*[see note] |
null |
* The processor stops after it finds the first TRUE. Hence there's an asymmetry between
T and null
and null and T
.
not
Syntax:
not expression1
The logical not
operator
implements the following truth table for expression1
and not expression1
.
expression1 |
not expression1 |
---|---|
F |
T |
T |
F |
null |
null |
Logical Functions
The logical functions available in item rules are listed below.
assignedToOrg
Syntax:
assignedtoOrg("org_code")
In a validation expression, returns TRUE if the item is assigned to the specified organization.
Example:
In the following example, when the item class of the item is Extra Data Servers, the organization can't be S2.
Severity: Reject
If Expression: [Item].[Item Basic].[Item Class] == "Extra Data Servers"
Validation Expression: !assignedtoOrg("S2")
assignedtoCatalog
Syntax:
assignedToCatalog(Catalog[CatalogCode].Category[CategoryCode])
In a validation expression, returns TRUE if the item is assigned to the specified catalog and category.
Example:
In the following example, if an item is assigned to the catalog Ladies Wear and the category Summer, it can't be assigned to catalog Kids and category Summer.
Severity: Reject
If Expression:
assignedtoCatalog(Catalog[LadiesWear].Category[Summer])
Validation Expression:
!assignedtoCatalog(Catalog[Kids].Category[Summer])
component_type
Syntax:
component_type("typename1", "typename2", ...)
In a validation expression that checks the component types for a structure, returns TRUE if the components associated with the structure are valid. The argument is a list of valid user item types for the components.
When creating a rule that checks the component types for a structure, you must select the Valid Component Rules check box in the Create Rules dialog box.
Unlike other validation rules, rules that validate components don't have a Severity.
Example:
In the following example, when the structure is Primary,
only type1
and type2
can be used as components of the structure.
If Expression: [Structure].[Structure Attributes].[Structure Name] == "Primary"
Validation Condition: component_type("type1","type2")
exists
Syntax:
exists(Boolean_expression)
Loops through the rows of the entities used in Boolean_expression
and returns TRUE if the
expression is satisfied for any of the rows.
You can use exists()
on the following entities:
-
relationships (related item relationships and cross-references)
-
structures
-
multirow attribute groups
Example expressions:
The following expression loops through all the structures on an item and returns TRUE if the any structure has the name "ManufacturingBOM".
exists([Structure].[Structure Attributes].[Structure Name] == "ManufacturingBOM")
The following expression validates whether a particular relationship exists for an item:
exists([Relateditem.[RelateditemMain[.[Type] == "Up-sell")
The following expression verifies whether a row exists in a multirow attribute group:
exists(isNull([Item].[Ingredients].[Ingredient Name]) == false)
Example rules:
The following rule verifies that if the item attribute Pack Type
is specified, then the GTIN attribute GTIN
can't be null
If Expression:
isNull([Item].[Main].[PACK TYPE]) == false
Validation Condition:
exists(isNull([GTIN].[GTIN Main].[GTIN])) == false
The following rule verifies that if the value of
the attribute TM
is US
, then the GTIN relationship must be with a Customer named
USFDA.
If Expression:
[Item].[Group1].[TM] == "US"
Validation Condition:
[GTIN].[GTIN Main].[Party Type] == "Customer" AND
[GTIN].[GTIN Main].[Party Name] == "USFDA"
from_item_class
Syntax
from_item_class ("item class name")
Invoked when the item class of an item is being changed.
In a validation expression, returns TRUE if the name of the original
item class matches "item class name"
, which must be enclosed in quotation marks.
Example:
The following example returns TRUE if the original
item class is TCParent
:
FROM_ITEM_CLASS("TCParent")
Combined example:
The following example prevents changing the item class of an item from Pneumatic_Pumps to Hydraulic_Pumps.
Severity: Reject
If Expression:
FROM_ITEM_CLASS("Pneumatic_Pumps") && TO_ITEM_CLASS("Hydraulic_Pumps")
to_item_class
Syntax
to_item_class("item class name")
Invoked when the item class of an item is being changed.
In a validation expression, returns TRUE if the name of the new item
class matches "item class name"
, which
must be enclosed in quotation marks.
Example:
The following example returns TRUE if the new item
class is TCCHLDVR
TO_ITEM_CLASS("TCCHLDVR")
Descriptive Flexfields
Descriptive flexfields don't belong to any attribute
group, and are accessed using the FlexField
segment code.
[<Entity Name>].Flexfield[<Flexfield segment code>]
Example:
[ChangeHeader].Flexfield[Product__Line]
Comparison Operators
The comparison operators available in item rules are listed below.
-
==
(equals) -
!=
(not equals) -
<
(less than) -
<=
(less than or equal) -
>
(greater than) -
>=
(greater than)
Comparison operators compare two Boolean expressions
and return TRUE or FALSE, depending on the result of the comparison.
If one or both expressions are null, then the comparison returns null.To
check for null values, use the comparison function isnull
.
String comparison is case-insensitive. For case-sensitive
comparison use the string function compare
.
Syntax:
expression1 == expression2 (equals
expression1 != expression2
expression1 < expression2
expression1 <= expression2
expression1 > expression2comp
expression1 >= expression2
isnull
Syntax:
isnull(expression)
Returns TRUE if its argument is null, returns FALSE otherwise. This function lets you explicitly test whether a value is null. Unlike other functions, it's not ignored if the value of the argument is null.
The logical function isnull()
implements the following truth table for expression
.
expression |
isnull(expression) |
---|---|
null |
T |
not null |
F |
nvl
Syntax:
nvl(expression,replacement-expression)
If expression
is null
or an empty string, returns replacement-expression
.
Example:
The following example returns an empty string if
the attribute Attr1
is null.
nvl([Item].[AttrGrp1].[Attr1], "")
In a scenario such as generating an item description
based on a large number of extensible flexfield attributes, it can
be inconvenient to use the isnull()
function when you want rules to keep executing even if one or more
of the used attributes is null, because isnull()
returns a Boolean value, which must be handled individually for
each attribute. The following example concatenates a series of attribute
values into a long description, and uses nvl()
to insert an empty string into the description where any of the
referenced attributes is null:
"Pipe Non-Metallic" +
":OUTSIDE DIAMETER:" + nvl([Item].[Pipe:Non-Metallic].[Outside Diameter],"") +
":NOMINAL SIZE:" + nvl([Item].[Pipe:Non-Metallic].[Nominal Size],"") +
":COLOR:" + nvl([Item].[Pipe:Non-Metallic].[Color],"")