How to Show customerId Value from customerGroupEntry Picker in Outputs

Let's assume you want to show the customerId value in the outputs. 

If you used just api.customerGroupEntry(), then the result in UI would be shown as e.g., "CG['customerId' = '60838']".

The correct procedure to display the value '60838' is:

  • Use api.getElement("CustomerGroup").customerFieldValue, depending on what is in the CustomerGroup element.
  • First define the CustomerGroup element, set the Display Mode to 'Never':

    CustomerGroup
    api.customerGroupEntry()
  • Then in any other element doing the calculations, use a syntax check.
    Also, set the Display Mode of this element to 'Quoting' at least.

    SomeOtherElement
    if (api.isSyntaxCheck()) return //as the first line
    if (api.getElement("CustomerGroup").customerFieldName == "customerId") {
      return api.getElement("CustomerGroup").customerFieldValue
    }

About Syntax Check

It is used in two use cases:

  1. Anytime you save a formula, it checks whether the Groovy code is well formed and that the code does some additional mocking of dependencies of the current element (it usually tries to add a neutral element of the type but if it cannot infer the type, it will assume the BigDecimal type). 
    So in this case, the syntax checker is unable to infer the return type of the expression api.getElement("CG") and will decide to put there a new BigDecimal(1).
  2. Usually any logic is run twice. In the first run, it just needs to see all calls to the methods which define input params (and so the isSyntaxCheck is set to true). Otherwise it is a normal logic run and this variable is set to false. The first run is really needed for the system to know what inputs the logic will generate.

For more details on isSyntaxCheck see Miscellaneous Functions.