Miscellaneous Functions

The following api. functions are available:

Name and Link to API DocCode Example
abortSyntaxCheckEnables to skip input generation if the user knows that there are no inputs to be evaluated in the subsequent elements of the logic. It helps to save computation time for more complex logics if all the inputs are created in the first elements of the logic.
addWarning
api.addWarning("Folders added!")

Available for both header logic (warning displayed in the Messages section) and line item logic (warnings displayed next to the line item).

boundCall
Product extensions
// Get records from 'LocalMaterialData' PX table by a certain attribute9 value
def request = """
  {
      "operationType" : "fetch", 
      "startRow" : 0, 
      "endRow" : 300, 
      "textMatchStyle" : "exact", 
      "data" : {
          "operator" : "and", 
          "_constructor" : "AdvancedCriteria", 
          "criteria" : [
              {
                  "fieldName" : "attribute9", 
                  "operator" : "iEquals", 
			   	  "value" : "${material13}"
              }
          ]
      }, 
      "oldValues" : null
  }"""
def response = api.boundCall("aasecP", "productmanager.fetch/*/PX/LocalMaterialData", request).responseBody.response
How to revoke a quote
if (api.isInputGenerationExecution()) {
	return
}

def response = api.boundCall("ad-brazil", "quotemanager.revoke/241.Q", "").responseBody.response

Important: The partition must be configured as a bound partition in the configuration.

(info) Please read also the Avoid api.boundCall article in Knowledge Base.

(warning) isInputGenerationExecution is supported from version 10.0. In older versions use isSyntaxCheck.

contextByLabel
contextNameNote: Does not work for Rebate Agreements line items and Rebate Records.
contextTypeNote: Does not work for Rebate Agreements line items and Rebate Records.
currentPartitionName
emitPersistedObject
emitRebateRecords
entityRef
evalExpression
filterFromMap
findCustomersInGroup
findWorkflowInfo
getBinding
getBoundPartitionNames
getCalculationContext
getCustomerIdsFromCustomerGroup

Returns a list of customer IDs based on the definition of the customer group.

def custg = api.customerGroupEntry()
def list = api.getCustomerIdsFromCustomerGrou(custg)
return list
getElement

Gets the result of a previous logic element.

  1. Given that you have a calculation logic with elements
    • Total_Sales
    • Margin
  2. When the logic of element "Margin" contains code

    def totalSales = api.getElement("Total_Sales")
    Then the variable totalSales contains result of element "Total_Sales".

Important: When saving the logic (during the input generation mode), this function will always behave as if it returned BigDecimal, even if the element returns a completely different data type. This can cause a problem during the "save" operation, if you are using the result as a Map, for example.

(tick) To simplify your code, you can use out.<element name> or output.<element name> instead of api.getElement. Example:

def totalSales = out.Total_Sales
getId
getSkusFromProductGroup

Returns a list of SKUs based on the definition of the product group.

def prodg = api.productGroupEntry()
def list = api.getSkusFromProductGroup(prodg)
return list
isDebugMode

Returns true if logic is called via UI debug/test exec mode.

@return true if executed in debug mode

When testing/debugging your code in the Test Drive, sometimes your code runs in a different context, than when it is executed in the real environment. In such a situation, it could be handy to identify that it runs in the Test Drive and make a manual input instead of taking data from the context, which is different than expected.

if (api.isDebugMode()) {
    customerId = "40101610"
} else {
    customerId = api.currentItem("customerId")
}
isDistributedMode
isSecondPass

isInputGenerationExecution

(formerly isSyntaxCheck)

Returns true if the logic is executed in the input generation (or parameter determination) mode (i.e., typically when you are trying to save the logic).

This function is mainly used to fix problems when saving a calculation logic in the logic editor. The trouble is, that  the validator, which runs before saving, executes your code to identify possible run-time issues. If it detects an error, it does NOT save the logic.

For example, when your logic element returns something else than BigDecimal (a Map, for instance), you have a problem, because the validator expects the function api.getElement() to return a BigDecimal.

The workaround could be using the following construction:

def pli = api.isInputGenerationExecution()? [:] : api.getElement("TargetPricePLI")

Important: Some users tend to block checking the code of the whole element (using if (api.isInputGenerationExecution()) return as the first line), but that is NOT advisable. There can be a real problem somewhere else in the code, which you will find out only in the runtime.

(info) For an example of use, see the Knowledge Base article How to Show customerId Value from customerGroupEntry Picker in Outputs.

(warning) isInputGenerationExecution is supported from version 10.0. In older versions use isSyntaxCheck.

jsonDecode
jsonDecodeList
jsonEncode
logInfo

Writes a message into the log file of the server node, on which the code is executed.

The log file can be accessed via the menu Administration > Logs.

api.logInfo("Adding LPG " + counter + " of " + size + " with label", lpg)

Note: Ensure that the logging from logic is enabled – see the menu: Administration > Configuration > General Settings > Allow Groovy logging into system log.

logWarn

Writes a message into the log file of the server node, on which the code is executed.

The log file can be accessed via the menu Administration > Logs.

api.logWarn("LI.Discount maximum discount",max)

Note: Ensure that the logging from logic is enabled – see the menu: Administration > Configuration > General Settings > Allow Groovy logging into system log.

multiKey
newController
putGlobal
random
removeSharedCache
resetSKUContextSwitch
sendEmail
setSharedCache
switchSKUContext
throwException
trace

Generates a trace message that can be used in the logic test drive.

  1. Given you have a calculation logic with a Groovy element containing the following code:

    api.trace("competitorName", null, competitorName)
    api.trace("competitorName", "", competitorName)
    api.trace("Current month - Last month", currentMonth, lastMonth)
  2. When you run the calculation logic using the Test Logic (Debugger), then you get:
uuid
walkFilter

Found an issue in documentation? Write to us.

Â