Skip to main content
mollyn6512
Known Participant
Aug 23, 2024 2:34 AM UTC
Solved

Support explaining how this code works

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
        )
      )

    kumara0180
    Participating Frequently
    Aug 23, 2024 2:56 AM UTC

    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
    Participating Frequently
    Aug 23, 2024 2:56 AM UTC

    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
    Participating Frequently
    Aug 23, 2024 4:44 AM UTC

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

    konduruc733182
    Inspiring
    Aug 23, 2024 5:40 AM UTC

    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
    Aug 23, 2024 6:44 AM UTC

    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?