IGFC rule scripting guide for flexible output integration

These are the different statements available:
  • Set
  • Variable Assignment
  • If Else If
  • For Every
  • Attribute-value Assignment

Set

This statement is used to define a new variable and assign an initial value.

Syntax
set variable_name = initial_value
Argument Description
variable_name

Name of the variable (composed of letters and digits).

initial_value
Possible values:
  • Number
  • Text enclosed in double quotes

Examples:

set itemUnitVal = 0
set itemUnitCd = "BOX"
set custId = ""

Variable Assignment

This statement is used to define a new variable and assign an initial value.

Syntax:
set variable_name = new_value
Argument Description
variable_name

Name of the variable (composed of letteName of the variable (composed of letters and digits) initially declared from set statement .

new_value
Possible values:
  • Number
  • Text enclosed in double quotes
  • Registered attribute of the relevant master data or transactional BOD
  • A defined expression of the relevant master data or transactional BOD
  • Rule setup value such as Rule.ruleSndrErp (for Sender Entity) or Rule.ruleRcvrErp (for Receiver Entity).
  • Another variable
  • An arithmetic computation involving any of the above-mentioned values (numeric data type only) as operands.

Examples:

custId = CustomerID
salesAmount = PoLine.lnTotAmt * RateNumeric

If Else If

This statement is used to control the conditional execution of statements.

Syntax:
If (value_source1 == value_source2) {
// statement block
}
If (value_source1 != value_source2) {
// statement block
} else {
// statement block
}
If (value_source1 >= value_source2) {
// statement block
} else if (value_source1 < value_source2) {
// statement block
}
Argument Description
condition
Possible values:
  • Number
  • Text enclosed in double quotes
  • Registered attribute of the relevant master data or transactional BOD
  • A defined expression of the relevant master data or transactional BOD
  • Rule setup value such as Rule.ruleSndrErp (for Sender Entity) or Rule.ruleRcvrErp (for Receiver Entity)
  • Another variable
Available conditional operators:
  • == (equal)
  • != (not equal)
  • > (greater than)
  • >= (greater than or equal)
  • < (less than)
  • <= (less than or equal)
Available logical operators to combine condition statements:
  • and
  • or

Use parenthesis () to enclose a condition statement and to specify the order of evaluation in combined conditions.

Note: An open curly brace immediately follows that of condition statement.

Examples:

If (SoLine.supplierPartyId == "VEN-100") {
// statement block
}
If (InvLine.unitPriceAmtCurr != AeCurrency) {
// statement block
} else {
// statement block
}
If (TaxRate >= 0.30) {
// statement block
} else if (TaxRate < 0.10) {
// statement block
}

For Every

This statement is used to repeat the execution of a block of statements for every occurrence of a repeating component in the input master data or transactional business document.

Syntax:
for every repeating_component {
// statement block
}
Argument Description
repeating_component

Registration name of a repeating component of the relevant input master data or transactional business document referenced within the ‘for every’ statement.

Examples:

for every PoLine {
// statement block
}
for every PoLineItem {
// statement block
}

Controlling the repetition of for every statement

A counter can be used to limit the execution of a block of statement in a rule script. This applies to generation of a single or limited number of a component of an output document that references a repeating attribute in the for every statement.

For example, a single header component need to be generated for the output Sales Order document, with Purchase Order as the input document. Part of the desired output header component is a field that references a value from the PurchaseOrderLine which repeats multiple times in the document. Thus, the PurchaseOrderLine component need to have its own for every statement before the attribute value assignment for the SalesOrderHeader such as:

for every PoLine {		
		"soHead": {    		
			//statement block
                }

Without a control syntax that limits the creation of the header component, the output document will have as many headers as there are input lines following above statement. Create a variable that refers to the execution count and an if condition that validates whether to run the statement block.

Argument Description
variable_name Name of the variable that refers to the counter
initial_value / new_value Numeric value that is used in conjunction with the condition statement
condition Matches the counter variable against a numeric limit that determines when to run a block of statement

Example:

set headerCount=0
	
    for every PoHead {		
        for every PoLine {		
            if (headerCount == 0) {
			                   "soHead": {    		
					                     //statement block
                		         }		
                		        "soLine": [
                    			  headerCount = 1
            			    }	
					                    //statement block
            }
          }
				                 if(headerCount == 1) {
                		         ] 
                    			  }

In the above example, an soHead component will only be created when the value of the variable headerCount equals 0. Note that after the execution of the first statement block for soHead, the headerCount is assigned with a value of 1 which stops the creation of another soHead.

Statements specific to search template type expressions with multiple search results

Specify the attribute to be retrieved by the expression among the multiple search results using the each and @ statements.

Each

This statement is used to repeat the execution of a block of statements for each search result.

@

This statement is used to assign the search result attribute to a specific variable. The syntax must include the statement @ and the name of the expression.

Syntax
each Expression {
variable_name = Expression@attributeName
variable_name = Expression@attributeName
// statement block
}
Argument Description
Expression

Name of the expression for the user-defined search template returning multiple search results.

variable_name

Name of the variable (composed of letters and digits). Must be unique for each search result attribute.

The variable name will be assigned as the source value of an attribute of the output business document.

Examples

Argument Description
Expression

PoItemDetail (search template name is getPoItemDetail with search results itemTrackingInd and itemUnitVal).

variable_name

trackInd for search result attribute itemTrackingInd unitVal for search result attribute itemUnitVal

value
Possible values:
  • Number
  • Text enclosed in double quotes
  • Registered attribute of the relevant master data or transactional BOD
  • A defined expression of the relevant master data or transactional BOD
  • Rule setup value such as Rule.ruleSndrErp (for Sender Entity) or Rule.ruleRcvrErp (for Receiver Entity)
  • A local variable
enclosures
Possible values are:
  • { } - curly brace. Used to group attribute-value assignments.
  • [ ] - square bracket. Used when the grouping element is a repeating attribute. The open square bracket immediately follows that of the grouping element and precedes the statement for the actual attribute-value assignment, and the conditions and loops, if applicable.

These must be observed in using the [ ] enclosure:
  • At least one [ ] enclosure set is required in a rule script.
  • Write the related ‘For every’ statements after the "grouping element ": [

  • When a repeating attribute exists within a grouping element, the attribute:value assignment for that repeating attribute must not be written last. Another attribute:value assignment for a non-repeating attribute must follow.

Note:  Enclosures must be in their proper position. This is important especially for multiple rules of one type of input document. When enclosures are not properly placed, the inbox status field in Data View will display an Error status for rules that were successfully processed.
each PoItemDetail {
trackInd = PoItemDetail@itemTrackingInd
unitVal = PoItemDetail@itemUnitVal
// statement block
}

Attribute-value assignment

This statement is used to define the value for each field in the output business document. The parameters are attribute-value pairs, separated by a comma.

Syntax
"grouping_element": {
"attribute": value,
"attribute": {
"attribute": value
}
},
"grouping_element": [
{
"attribute": value,
"attribute": value
}
{
"attribute": value,
"attribute": value
}
]
Argument Description

grouping_element

Registered attribute of the output master data or transactional business document that refers to the root attribute of the BOD registration record. This attribute does not have a value, but contains the rest of the attributes in the registration group.

A grouping element is named after the BOD registration, only that it begins with a lowercase letter.

attribute

Registered attribute of the relevant output master data or transactional business document that will be defined with a value source. It can also refer to a component that contains the attribute to be defined.

Note: 
Attribute-value assignment must be defined in the same order as they are structured in the BOD instance. For example:
  • Line component before another grouping element within the same line component
  • Attribute field before filters within the same attribute tag
"grouping_element": {
                  "attribute": value,
                  "attribute": [
                      {
                          "attribute": value,
                          "attribute": value
                      },
                      {
                          "attribute": value,
                          "attribute": value
                      }
                  ],
                  "attribute": value
}
Here is an example rule script for a purchase order business document that is transformed into a sales order document:

1    set salesAmount = 0
2    set trackInd = ""
3    set unitVal = ""
4       for every PoHead {
5           if (PoHead.poType == "IC") {
6               salesAmount = PoHead.extAmt * RateNumeric
7                   "soHead": {
                         "documentDate": PoHead.docDate,
                         "statusCode": PoHead.statCd,
                         "statusListId": "Sales Order Status",
                         "hdrTotAmt": salesAmount,
                         "hdrTotAmtCur": TargetBaseCur,
                         "soPoRef": {
                                 "soPoRefId": PoHead.poNuM 
                         },
8                   }
9                 "soLine": [
10                    for every PoLine {
11                    salesAmount = PoLine.lnExtAmt * RateNumeric
12                    for every PoItemId {
13                    each PoItemDetail {
                      trackInd = PoItemDetail@itemTrackingInd
                      unitVal = PoItemDetail@itemUnitVal
14                       {
15                         "itemId": ItemID,
                           "lnTotAmt": salesAmount,
                           "lnTotCur": TargetBaseCur,
                           "lnUnitTotAmt": unitVal,
                           "lnUnitTotCur": PoLine.unitPriceCur,
                           "quantity": PoLine.qty,
                           "quantityUnitCd": PoLine.qtyUCd,
                           "lnUserTrackInd": trackInd
16                                          }
17                              }
18                              }
19                           }
20                       ]
21                   }
22               }

Lines 1-3 will create three local variables, namely salesAmount, trackInd and unitVal.

Using the if condition in Line 5 that validates the transaction type for the input purchase order, an output business document will be generated with fields defined in Lines 6-16.

Line 6 defines the variable salesAmount as the product of multiplying the extended amount from the input purchase order header document with the exchange rate numeric determined by the expression RateNumeric. This variable is then assigned as the value for sales order header total amount in Line 7.

Using the for every statement in Lines 10 and 12, all assignments from Line 14 runs for every purchase order line and item ID from the input business document.

Line11 defines the variable salesAmount as the product of multiplying the extended amount from the input purchase order line document with the exchange rate numeric determined by the expression RateNumeric. This variable is then assigned as the value for sales order line total amount in Line 14.

Additional variable definition is stated in Line 13 that is coming from an expression that returns multiple search result. Each search result is assigned to variables trackInd and unitVal, which is then assigned as a value source in Line 14.

Statements specific to REST API type expressions with multiple result keys

REST API type expressions with multiple result keys can be assigned in the rule script as a value source for a defined variable or as a definition of an output attribute field in the attribute-value assignment statements. It can also be a value for comparison in an if condition.

To use this type of expression, specify the attribute to be retrieved by the expression among the multiple result keys using the @ statement. The attribute name refers to the values displayed in the result keys list box.

Syntax

As a value source for a defined variable:

variable_name = Expression@attributeName

As a value source for an output attribute field:

“attribute”: variable_name, …

Alternatively, the expression with @ statement can also be assigned directly to the output attribute field:

If (value1 relationalOperator value2) {

//statement block

Where value1 or value2 may refer to:
  • The variable name of the REST API type expression with an @ statement
  • The REST API type expression with an @ statement
Note: REST API type expressions with single result keys need not use the @ statement.