Skip to main content
January 31, 2024
Question

I want to iterate a!save() expression 10 times

  • January 31, 2024
  • 9 replies
  • 0 views

I want to iterate a a!save() expression for 10 (n times) when I press a button

    9 replies

    venkatrea696188
    January 31, 2024

    a!localVariables(
      local!X,
      {
      a!buttonArrayLayout(
        buttons: {
          a!buttonWidget(
            label: "Button",
            style: "OUTLINE",
            saveInto: a!forEach(
              items: enumerate(10)+1,
              expression: a!save(
                local!X[fv!index],fv!item
              )
            )
          )
        },
        align: "START",
        marginBelow: "NONE"
      )
    })

    What do you want to save using a!save() ?  Can you provide us with more details

    harshitb6843
    January 31, 2024

    [mention:995c759ada07435883c8572879d4840b:e9ed411860ed4f2ba0265705b8793d05] You shouldn't be doing that unless you are sure that there is no better way to do what you are trying to achieve. 

    For example, the above code doesn't need a forEach loop if you just want to update the items of an array. It can be simplified as

    a!save(
        local!X,
        enumerate(10)+1
      )

    But if you have a particular requirement which cannot be solved without a loop, then you have the code from Venky. 

    stefanhelzle0001
    January 31, 2024

    A foreach would do that. But what do you want to achieve?

    January 31, 2024

    I want to sort a number array in Appian without using sort function

    konduruc733182
    January 31, 2024

    Hello [mention:995c759ada07435883c8572879d4840b:e9ed411860ed4f2ba0265705b8793d05] 
    You will have to use a!forEach() and run your a!save()(Not recommended). Also do you have any particular variable that defines the number of iterations that has to be performed? 
    What will this a!save() perform exactly?
    If the Rule Input or Local variable that you are going to use for the target is same, You don't need to do the loop. May be a better explanation of your requirement would help all of us to give a better solution.

    January 31, 2024

    I want to sort a numbers array in Appian without using sort function

    harshitb6843
    January 31, 2024

    This has been discussed on community quite a lot of times now - community.appian.com/.../function

    if(
      a!isNullOrEmpty(ri!inputArray),
      {},
      a!localVariables(
        local!data: a!forEach(
          items: ri!inputArray,
          expression: { value: fv!item }
        ),
        todatasubset(
          local!data,
          a!pagingInfo(
            startIndex: 1,
            batchSize: - 1,
            sort: a!sortInfo(
              field: "value",
              ascending: or(ri!ascending)
            )
          )
        ).data.value
      )
    )