how to loop a!completeTask function and save the result

Certified Senior Developer

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

  Discussion posts and replies are publicly visible

Parents
  • 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"
    )
Reply
  • 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"
    )
Children
  • 0
    Certified Senior Developer
    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
  • 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.
  • Hello Kevin.I have a similar situation where i have task Ids now in the process but not sure how to call a!complete task in the process model.Please let me know how to may tasks complete using process model and complete task smart service.Any screenshot would be appreciated.
  • 0
    Certified Senior Developer
    in reply to RajHasti

    Hi Raj,

    You can use complete task smart service in process model passing task id and inputs of the tasks to the smart service as follows

    TaskId:12,

    TaskInputs:

    {

    id:12,

    name:raj,

    button:true()

    }

  • Hi Rajesh,

    We had the same requirement I had done the following code for closing open tasks by using Complete task smart service. In primary buttons, I had set like below..i have to close tasks by selecting open tasks after selecting i will get  ri!processID number in rule input but instead of processes id(TaskID) number i am getting other numbers like supplier ID...

    Please help  me with needfull changes...

    a!buttonLayout(
    primaryButtons: a!buttonWidget(
    label: "Close Task",
    submit: true(),
    confirmMessage: "Are you sure you want to close Task?",
    skipValidation: true,
    style: "PRIMARY",
    value: true(),
    saveInto: {
    a!save(
    ri!processId ,
    local!selectionIndex
    )
    },

     . 

    a!localVariables(
      local!channelManagerData: rule!BGH_QE_GetChannelManagerID(),
      local!dataSubset: rule!BGH_getSupplierTaskPropertyReports(),
    
      local!selectedTask,
      local!data,
      local!selectionIndex,
      local!supplierID,
      local!selectedSupplierID,
      local!selectedSupplierData,
      local!channelManagerChoiceLabels:index(local!channelManagerData,"name_text",{}),
      local!channelManagerChoiceValues:index(local!channelManagerData,"channelManagerID_int",{}),
      {
        a!sectionLayout(
          contents: {
            a!columnsLayout(
              columns: {
                a!columnLayout(
                  contents: {
                    a!dropdownField(
                      label: "Select Channel Manager",
                      choiceLabels: append(local!channelManagerChoiceLabels,"Others"),
                      choiceValues: append(local!channelManagerChoiceValues,0),
                      placeholderLabel: "--Select value--",
                      value: local!selectedTask,
                      saveInto: {
                        local!selectedTask,
                        /*a!save(local!selectedSupplierID,if(local!selectedTask=0,*/
                        /*"Value",*/
                        /*local!selectedTask)*/
                        /*),*/
                        a!save(local!data,index(local!datasubset,wherecontains(tostring(local!selectedTask),touniformstring(index(local!datasubset,"c12",""))),{})),
                        a!save(local!supplierID,union(index(local!data,"c11",""),index(local!data,"c11",""))),
                        a!save(local!selectedSupplierID, null),
                        a!save(local!selectedSupplierData,null),
                        a!save(local!selectionIndex, null)
                      }
                    )
                  }
                ),
                a!columnLayout(
                  contents: {
                    if(
                      rule!APN_isBlank(
                        local!supplierID
                      ),
                      a!textField(
                        value: "No Task is available on corresponding channel Manager",
                        readOnly: true,
                        showWhen: not(
                          rule!APN_isBlank(
                            local!supplierID
                          )
                        )
                      ),
                      a!dropdownField(
                        label: "Select Supplier",
                        choiceLabels: 
                        if(
                          tointeger(local!supplierID)=0,
                          "Other Supplier",
                          a!forEach(
                            items: local!supplierID,
                            expression: rule!BGH_QE_getSupplier_ID(fv!item)
                          )
                        ),
                        choiceValues: a!forEach(items: local!supplierID,
                        expression: fv!item
                        ),
                        placeholderLabel: "Select Required Supplier",
                        value: local!selectedSupplierID,
                        saveInto: {
                          local!selectedSupplierID,
                          a!save(
                            local!selectedSupplierData,
                            rule!BGH_getSupplierTaskPropertyReports(
                              
                              managerID: local!selectedTask,
                              supplierID: local!selectedSupplierID
                            )
                          ),
                          a!save(local!selectionIndex, null)
                        },
                        showWhen: not(
                          rule!APN_isBlank(
                            local!supplierID
                          )
                        )
                      )
                    )
                  }
                )
              },
              marginBelow: "STANDARD"
            ),
            if(
              rule!APN_isBlank(
                local!selectedSupplierData
              ),
              {},
              a!gridField(
                label: "Select Tasks",           
                data: local!selectedSupplierData,
                columns: {
                  a!gridColumn(
                    label:"Task Name",
                    value: index(fv!row,"c0","")
                  ),
                  a!gridColumn(
                    label: "Process Name",
                    value: index(fv!row,"c2","")
                  ),
                  a!gridColumn(
                    label: "Status",
                    value: if(
                      index(
                        fv!row,
                        "c0",
                        ""
                      ) = "0",
                      "Open",
                      "Assigned"
                    )
                  ),
                  a!gridColumn(
                    label: "Start Time",
                    value: if(
                      rule!APN_isBlank(
                        fv!row.c3
                      ),
                      "",
                      text(
                        index(
                          fv!row,
                          "c3",
                          ""
                        ),
                        "DD/MM/YYYY HH:MM A"
                      )
                    )
                  ),            
                },
                pageSize: 10,
                selectable: true(),
                selectionValue: local!selectionIndex,
                selectionSaveInto: local!selectionIndex
              )
            )
          },
          divider: "BELOW"
        ),
        if(
          or(
            isnull(local!selectionIndex),
            length(local!selectionIndex) >0
          ),
          a!richTextDisplayField(
            label:"No Open tasks to close",
            showWhen: if(
              or(
                isnull(local!supplierID),
                length(local!supplierID) = 0
              ),
              if(
                not(isnull(local!selectedTask)),
                true,
                false
              ),
              false
            )
          ),
          {}
        ),
        a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Close Task",
            submit: true(),
            confirmMessage: "Are you sure you want to close Task?",
            skipValidation: true,
            style: "PRIMARY",
            value: true(),
            saveInto: {
              a!save(         
               ri!processId ,
              local!selectionIndex  
              )
            },
            disabled: rule!APN_isEmpty(local!selectionIndex) > 0
          ),
          secondaryButtons: {
            a!buttonWidgetSubmit(
              label: "Cancel",
              style: "NORMAL",
              confirmMessage: "Are you sure?",
              /*value: "Yes",*/
              saveInto: ri!buttonValue,
              value:true(),
              skipValidation: true
            )
          }
        )
      }
    )

    Thanks..

  • 0
    Certified Senior Developer
    in reply to satishk0001

    Hi ,

    For using complete task smart service we should pass particular process taskId's and task inputs in Anytype to complete the task(you mentioned you are getting supplier id,if it is from your application it won't work. to complete task you must and should pass tp!id of particular task to the complete task smart service)  

    in your case if you want to complete multiple tasks on click of a button 

          In saveInto use a!startProcess and create process as shown in above comments and you can pass multiple taskid's to the smart service

    I hope this helps your case

    Regards,

    Rajesh Pamisetty