how to loop a!completeTask function and save the result

how to loop a!completeTask function and save the result

 

i have list of task ids and list of  task inputs,on click of a button it should be able to complete tasks using a!completeTask function in a loop,but am unable to do it in a loop.Can anyone help on this? 

 a!buttonWidget(
label: "complete task",
saveInto: {
/* how to write the below function in loop and how to save it using a!save function*/
a!completeTask(
taskId: tointeger(ri!selectedTaskIDs ),
taskInputs: { input: ri!taskInput },
onSuccess: a!save(ri!message, "Updated Successfully"),
onError: a!save(ri!message, "Already Updated")
)
},
style: "PRIMARY"
)

 

 

Thanks in advance

  • Can you elaborate more on the exact problem you're facing when you're trying the loop? (Maybe with code snippets?) I'm guessing your problem is that you're not associating the task ids and task inputs properly in that one task id needs to correspond to multiple task inputs, so you may need an array of arrays for your task input to loop properly. A sample snippet would help us be able to provide a more detailed solution.
  • In reply to Kenneth Chen:

    a!buttonWidget(
    label: "complete task",
    saveInto: {
    /* how to write the below function in loop and how to save it using a!save function*/
    a!completeTask(
    taskId: tointeger(ri!selectedTaskIDs ),
    taskInputs: { input: ri!taskInput },
    onSuccess: a!save(ri!message, "Updated Successfully"),
    onError: a!save(ri!message, "Already Updated")
    )
    },
    style: "PRIMARY"
    )
  • You can use foreach to save something in loop
    a!buttonWidget(
    label: "complete task",
    saveInto: {
    /* how to write the below function in loop and how to save it using a!save function*/
    a!save(local!task,a!forEach(items:ri!selectedTaskIDs,expression:a!completeTask(
    taskId: tointeger(fv!item ),
    taskInputs: { input: ri!taskInput },
    onSuccess: a!save(ri!message, "Updated Successfully"),
    onError: a!save(ri!message, "Already Updated")
    )
    )
    )
    },
    style: "PRIMARY"
    )
  • In reply to jaisym:

    Thanks for the input,i have tried it earlier but an getting the following error


    Interface Definition: Expression evaluation error: An error occurred while executing a save: java.lang.IllegalStateException: A Value should not be the result of activation

    Can any one help me how to handle it?

    Thanks in advance
  • In reply to RajeshPamisetty:

    Only one smart service can be executed inside the saveInto of a component on an interface, per our documentation: docs.appian.com/.../executing_smart_services.html

    Since a!completeTask only takes a single taskId you won't be able to achieve what you are looking to do this way. Instead, you could start a process when the button is clicked that takes all the taskIds as a parameter and then loops through the taskIds with the Complete Task smart service inside that process.

 Discussion posts and replies are publicly visible