arraysconcatenationappian

The Appian way to add a derived field to a common data type on the fly?


Assume I have an Appian common data type (CDT) called myTask which contains multiple fields taskName, taskQuarter, taskYear, taskId saved in a local variable (of an Interface) which looks for instance as follows

+ data (List of dictionary)
  + (Dictionary)
    - taskName:    "Plant trees." (Text)
    - taskQuarter: 1              (Number (Integer))
    - taskYear:    2020           (Number (Integer))
    - taskId:      0              (Number (Integer))
  + (Dictionary)
    - taskName:    "Cut leaves." (Text)
    - taskQuarter: 2              (Number (Integer))
    - taskYear:    2020           (Number (Integer))
    - taskId:      1              (Number (Integer))

In the local scope (of the interface), I would like to have an additional field for all records called taskLongName which would be the following concatenation (in pseudocode):

taskLongName = taskName + " " + taskYear + " Q" + taskQuarter

How do I do that, please?


Solution

  • It turned out to be rather simple: Assuming that you have an expression rule myGetAllTasks() defined, you could put the initial list of dictionaries into local!allTasks. Next, we use Appian's a!forEach() function:

    a!localVariables(
    local!allTasks: rule!myGetAllTasks().data, 
    local!taskLongNames: 
      a!foreach(
        items: local!allTasks,
        expression: concat(
          fv!item.taskName, " for ",
          fv!item.processYear, " Q",
          fv!item.processQuarter
        )
      ),
      ... <-- Here comes the configuration (code) defining the actual interface
    )