Skip to main content
mollyn6512
August 23, 2024
Solved

Support explaining how this code works

  • August 23, 2024
  • 4 replies
  • 0 views

HI everyone, 

Could you help explain me how below code works? The character "_" is new to me and I cannot find any documentation for it.

 

apply(
        contains(
          index(
            local!childTask,
            "id",
            null
          ),
          _
        ),
        index(
          local!parent,
          "id",
          null
        )
      )

    Best answer by kumara0180

    first thing first, Apply function has been replaced with foreach. Or I would say Foreach is better way of implementing looping logics. 

    In your case, - would be replaced with value of the id from parent variable.

    You can implement same logic with 


    )

    a!forEach(
      items: index(
        local!parent,
        "id",
        null
      ),
      expression: contains(
        index(
          local!childTask,
          "id",
          null
        ),
        fv!item
      ),
    )

    4 replies

    kumara0180
    August 23, 2024

    first thing first, Apply function has been replaced with foreach. Or I would say Foreach is better way of implementing looping logics. 

    In your case, - would be replaced with value of the id from parent variable.

    You can implement same logic with 


    )

    a!forEach(
      items: index(
        local!parent,
        "id",
        null
      ),
      expression: contains(
        index(
          local!childTask,
          "id",
          null
        ),
        fv!item
      ),
    )

    karumurua531442
    August 23, 2024

    hi [mention:b18d9a2f367a407ca0cf8a9b71bef972:e9ed411860ed4f2ba0265705b8793d05]  '_ ' represents the current element being processed in the iteration.

    konduruc733182
    August 23, 2024

    Hello [mention:b18d9a2f367a407ca0cf8a9b71bef972:e9ed411860ed4f2ba0265705b8793d05] 

    apply() evaluates the given rule or function for all the items in the given list. Where in the apply the 'function' parameter is similar to the 'Expression' that you write in the a!forEach() but would only be a function here.

    The '_'  defines the item in the array against which the function would be evaluated. We use '_' to iterate all the items in the given list in the 2nd parameter of the apply(). 

    Also, Appian recommends to use the a!forEach() instead of apply() for better null handling.

    docs.appian.com/.../fnc_looping_apply.html

    stefanhelzle0001
    Brainy
    August 23, 2024

    Find the documentation here: https://docs.appian.com/suite/help/24.3/expression-advanced-evaluation.html

    Can you help me understand what this code is meant to do? What is the outcome and what is that outcome used for?