Other Functions

Functions

Once you've mastered the standard BML functions, you can move on to the other, advanced, functions. These advanced functions use Dictionaries and pull external information from external resources, using Data Tables and a couple of functions that are specific to either configuration or commerce.

This function returns the delimited string for array attributes with $,$ as the delimiter.

This function is only used for Configuration attributes.

Syntax:

getarrayattrstring(SingleArray arrayIdentifier)

Parameters:

Parameter Data Type Description

arrayIdentifier

String[] The given input array.

Return Type: String

Example of getarraystr:

getarrayattrstring example getarrayattrstring output example


This function retrieves the values of configuration attributes in Commerce.

Syntax:

getconfigattrvalue(configAttrVarname)

-OR-

getconfigattrvalue([documentNumber], configAttrVarname)

Parameters:

Parameter Data Type Description

[documentNumber]

Integer Optional: Represents the transaction number.

configAttrVarName

String Variable name of the configuration attribute from which you are retrieving data.

Return Type: String

In case of menu attributes, the returned value is the menu item variable name.

Example:

getconfigattrvalue example

In case of menu attributes, the returned value is the menu item variable name.
The System Attribute _config_attr_info has to be selected as a rule input. If it is not selected and getConfigAttrVal is used, a compile error is shown to the user.

Retrieves an old value for given variable name containing old value and document number.

Syntax:

getoldvalue(variableName [, documentNumber])

Parameters:

Parameter Data Type Description

variableName

String Variable name containing old value.

[documentNumber]

Integer Optional: Defaults to 1, which is the main document.

Return Type: String

It will return empty string for the following cases:

  • When it is called from debugger
  • If the document with the given document number does not exist
  • If the variable with the given variable name does not exist in the document

Examples:

pre1 = getoldvalue("_quote_bill_to_address");

pre2 = getoldvalue("_price_net_price", 2);


This function returns the status of the reason variable name in an approval sequence.

Syntax:

Integer getreasonstatus(String)

Parameters:

Parameter Data Type Description

reasonVarName

String This is the variable name of the reason within the approval sequence.

Return Type: Integer (associated with one of the following statuses):

  • BM_REASON_STATUS_INVALID: No reason exists in admin reason tree with given variable name.
  • BM_REASON_STATUS_INACTIVE: Reason exists in admin reason tree but the condition for the reason is not met, therefore no record for it exists in the user-side tree.
  • BM_REASON_STATUS_PENDING: Reason exists in the user-side reason tree and there are pending approvals.
  • BM_REASON_STATUS_APPROVED: Reason exists in the user-side tree and it is approved by all approvers, therefore the reason is completely approved.
  • BM_REASON_STATUS_REJECTED: Reason exits in user-side tree, but has been rejected by at least one approver.

This function generates unique IDs for assets tracked in Asset-Based Ordering. Every asset is tracked in ABO using an asset key. When a unique ID is generated, it becomes the asset key for an asset. The number of asset keys to generate is dependent on the count parameter in the function.

Syntax:

String[] getuuid(Integer count)

Parameter Data Type Description

count

Integer

The number of unique IDs to generate.

Example:

getuuid(2); // Generates string array with 2 unique IDs.

Output:

[6bafc278-25fd-495f-8360-67bcfb8776b0, 65abced9-5c47-47c6-bf18-ab96fb73935f]


This function invokes global table functions.

Syntax:

invoke(globalTableFunction, [delimitedData, [defaultData]])

Parameters:

Parameter Data Type Description

globalTableFunction

Function The table function to invoke.

[delimitedData]

String The parameters, passed as a delimited string.

[defaultData]

String  

Return Type: Boolean

Example:

The following script invokes the global function someGlobalFunction. The parameters are passed as a delimited string. If a valid string is not returned by someGlobalFunction, the default string is "error_in_rule"

params = "";
params = var_frequency + "~" + "model number";
return invoke("someGlobalFunction",params,"error_in_rule");

Evaluates whether a particular Object is null or not. Returns true if argument passed is null.

Syntax:

isnull(String (or Date (or Array or (dict))))

Parameters:

Parameter Data Type Description

obj

String, Date, Array, Dictionary The Object to examine for a null state.

Return: Boolean

Example:

isnull example

This evaluates to false.

If getconfigattrvalue is called for a non-existing attribute, it returns null. If the return value is passed to isnull, it will return true.


Writes an event to the Performance Log table, which is visible by filtering on "BML" for the Event Type. This logging will only occur when executed outside of the debugger.

Syntax:

logtime(tag, timeElapsed)

Parameters:

Parameter Data Type Description

tag

String The tag to be logged. This parameter has a 128 character limit. If more than 128 characters are passed into the function, the 129th and later characters are truncated.

timeElapsed

Integer The time elapsed for the event, saved in the log.

Return Type: Boolean


Prints into the console window of the Function Editor. Example Use Case:  For debugging.

Syntax:

print(String(or Array(or Dictionary(or Numeric(or Date(or Boolean))))) varName)

Parameters:

Parameter Data Type Description

varName

String, Array, Dictionary, Numeric, Date, or Boolean The item to print to the Function Editor console.

Return Type: Boolean

Examples:

To display "abba" in the console window in the Function Editor.

print("abba") 

To display [1,2,3,4,5] in the console window.

intArray = integer[]{1,2,3,4,5};
print(intArray); //

To display {key1=X, key2=Y} in the console window.

testDict =dict("string");
put(testDict,"key1","X");
put(testDict,"key2","Y");
print textDict;//

 

Notes

  • NULL and blank Integer values are treated as separate values:
    • NULL= 0
    • Blank = ""
  • Using NULL as an attribute value is strongly discouraged.
  • If you use logic that tests for NULL values in rule conditions or BML, confirm that the logic takes this difference into account.

Related Topics

Related Topics Link IconSee Also