<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>how to loop a!completeTask function and save the result</title><link>https://community.appian.com/discussions/f/user-interface/14328/how-to-loop-a-completetask-function-and-save-the-result</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/70238?ContentTypeID=1</link><pubDate>Wed, 30 Oct 2019 16:04:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:35eb6f9c-c2d5-42e6-9cbe-9e45a40bedb6</guid><dc:creator>rajesh pamisetty</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a class="internal-link view-user-profile" href="/members/satishk0001"&gt;satishk&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For using complete task smart service we should pass particular process taskId&amp;#39;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&amp;#39;t work. to complete task you must and should pass tp!id of particular task to the complete task smart service)&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;in your case if you want to complete multiple tasks on click of a button&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; In saveInto use a!startProcess and create process as shown in above comments and you can pass multiple taskid&amp;#39;s to the smart service&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I hope this helps your case&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Rajesh Pamisetty&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/70236?ContentTypeID=1</link><pubDate>Wed, 30 Oct 2019 15:47:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ff47d4b4-27d6-4cff-babc-495c15e3534e</guid><dc:creator>satishk0001</dc:creator><description>&lt;p&gt;Hi Rajesh,&lt;/p&gt;
&lt;p&gt;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&amp;nbsp; ri!processID number in rule input but instead of processes id(TaskID) number i am getting other numbers like supplier ID...&lt;/p&gt;
&lt;p&gt;Please help&amp;nbsp; me with needfull changes...&lt;/p&gt;
&lt;p&gt;a!buttonLayout(&lt;br /&gt; primaryButtons: a!buttonWidget(&lt;br /&gt; label: &amp;quot;Close Task&amp;quot;,&lt;br /&gt; submit: true(),&lt;br /&gt; confirmMessage: &amp;quot;Are you sure you want to close Task?&amp;quot;,&lt;br /&gt; skipValidation: true,&lt;br /&gt; style: &amp;quot;PRIMARY&amp;quot;,&lt;br /&gt; value: true(),&lt;br /&gt; saveInto: {&lt;br /&gt; a!save( &lt;br /&gt; ri!processId ,&lt;br /&gt; local!selectionIndex &lt;br /&gt; )&lt;br /&gt; },&lt;/p&gt;
&lt;p&gt;&amp;nbsp;.&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;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,&amp;quot;name_text&amp;quot;,{}),
  local!channelManagerChoiceValues:index(local!channelManagerData,&amp;quot;channelManagerID_int&amp;quot;,{}),
  {
    a!sectionLayout(
      contents: {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!dropdownField(
                  label: &amp;quot;Select Channel Manager&amp;quot;,
                  choiceLabels: append(local!channelManagerChoiceLabels,&amp;quot;Others&amp;quot;),
                  choiceValues: append(local!channelManagerChoiceValues,0),
                  placeholderLabel: &amp;quot;--Select value--&amp;quot;,
                  value: local!selectedTask,
                  saveInto: {
                    local!selectedTask,
                    /*a!save(local!selectedSupplierID,if(local!selectedTask=0,*/
                    /*&amp;quot;Value&amp;quot;,*/
                    /*local!selectedTask)*/
                    /*),*/
                    a!save(local!data,index(local!datasubset,wherecontains(tostring(local!selectedTask),touniformstring(index(local!datasubset,&amp;quot;c12&amp;quot;,&amp;quot;&amp;quot;))),{})),
                    a!save(local!supplierID,union(index(local!data,&amp;quot;c11&amp;quot;,&amp;quot;&amp;quot;),index(local!data,&amp;quot;c11&amp;quot;,&amp;quot;&amp;quot;))),
                    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: &amp;quot;No Task is available on corresponding channel Manager&amp;quot;,
                    readOnly: true,
                    showWhen: not(
                      rule!APN_isBlank(
                        local!supplierID
                      )
                    )
                  ),
                  a!dropdownField(
                    label: &amp;quot;Select Supplier&amp;quot;,
                    choiceLabels: 
                    if(
                      tointeger(local!supplierID)=0,
                      &amp;quot;Other Supplier&amp;quot;,
                      a!forEach(
                        items: local!supplierID,
                        expression: rule!BGH_QE_getSupplier_ID(fv!item)
                      )
                    ),
                    choiceValues: a!forEach(items: local!supplierID,
                    expression: fv!item
                    ),
                    placeholderLabel: &amp;quot;Select Required Supplier&amp;quot;,
                    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: &amp;quot;STANDARD&amp;quot;
        ),
        if(
          rule!APN_isBlank(
            local!selectedSupplierData
          ),
          {},
          a!gridField(
            label: &amp;quot;Select Tasks&amp;quot;,           
            data: local!selectedSupplierData,
            columns: {
              a!gridColumn(
                label:&amp;quot;Task Name&amp;quot;,
                value: index(fv!row,&amp;quot;c0&amp;quot;,&amp;quot;&amp;quot;)
              ),
              a!gridColumn(
                label: &amp;quot;Process Name&amp;quot;,
                value: index(fv!row,&amp;quot;c2&amp;quot;,&amp;quot;&amp;quot;)
              ),
              a!gridColumn(
                label: &amp;quot;Status&amp;quot;,
                value: if(
                  index(
                    fv!row,
                    &amp;quot;c0&amp;quot;,
                    &amp;quot;&amp;quot;
                  ) = &amp;quot;0&amp;quot;,
                  &amp;quot;Open&amp;quot;,
                  &amp;quot;Assigned&amp;quot;
                )
              ),
              a!gridColumn(
                label: &amp;quot;Start Time&amp;quot;,
                value: if(
                  rule!APN_isBlank(
                    fv!row.c3
                  ),
                  &amp;quot;&amp;quot;,
                  text(
                    index(
                      fv!row,
                      &amp;quot;c3&amp;quot;,
                      &amp;quot;&amp;quot;
                    ),
                    &amp;quot;DD/MM/YYYY HH:MM A&amp;quot;
                  )
                )
              ),            
            },
            pageSize: 10,
            selectable: true(),
            selectionValue: local!selectionIndex,
            selectionSaveInto: local!selectionIndex
          )
        )
      },
      divider: &amp;quot;BELOW&amp;quot;
    ),
    if(
      or(
        isnull(local!selectionIndex),
        length(local!selectionIndex) &amp;gt;0
      ),
      a!richTextDisplayField(
        label:&amp;quot;No Open tasks to close&amp;quot;,
        showWhen: if(
          or(
            isnull(local!supplierID),
            length(local!supplierID) = 0
          ),
          if(
            not(isnull(local!selectedTask)),
            true,
            false
          ),
          false
        )
      ),
      {}
    ),
    a!buttonLayout(
      primaryButtons: a!buttonWidget(
        label: &amp;quot;Close Task&amp;quot;,
        submit: true(),
        confirmMessage: &amp;quot;Are you sure you want to close Task?&amp;quot;,
        skipValidation: true,
        style: &amp;quot;PRIMARY&amp;quot;,
        value: true(),
        saveInto: {
          a!save(         
           ri!processId ,
          local!selectionIndex  
          )
        },
        disabled: rule!APN_isEmpty(local!selectionIndex) &amp;gt; 0
      ),
      secondaryButtons: {
        a!buttonWidgetSubmit(
          label: &amp;quot;Cancel&amp;quot;,
          style: &amp;quot;NORMAL&amp;quot;,
          confirmMessage: &amp;quot;Are you sure?&amp;quot;,
          /*value: &amp;quot;Yes&amp;quot;,*/
          saveInto: ri!buttonValue,
          value:true(),
          skipValidation: true
        )
      }
    )
  }
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thanks..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/65453?ContentTypeID=1</link><pubDate>Thu, 28 Mar 2019 10:11:38 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b63a795e-4fa8-4ac9-b5c5-04ed2d5985b0</guid><dc:creator>rajesh pamisetty</dc:creator><description>&lt;p&gt;Hi Raj,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can use complete task smart service in process model passing task id and inputs of the tasks to the smart service as follows&lt;/p&gt;
&lt;p&gt;TaskId:12,&lt;/p&gt;
&lt;p&gt;TaskInputs:&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;id:12,&lt;/p&gt;
&lt;p&gt;name:raj,&lt;/p&gt;
&lt;p&gt;button:true()&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/480x240/__key/communityserver-discussions-components-files/13/6675.Capture.PNG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/65297?ContentTypeID=1</link><pubDate>Thu, 21 Mar 2019 15:24:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:122aeaac-ebb3-47cb-b6bb-268c37277201</guid><dc:creator>RajHasti</dc:creator><description>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.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/64654?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 12:44:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4a93f0d7-7dac-4a87-a825-41e2f9b15b53</guid><dc:creator>Kevin Gajewski</dc:creator><description>Only one smart service can be executed inside the saveInto of a component on an interface, per our documentation: &lt;a href="https://docs.appian.com/suite/help/18.4/executing_smart_services.html"&gt;docs.appian.com/.../executing_smart_services.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Since a!completeTask only takes a single taskId you won&amp;#39;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.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/64653?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 11:26:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:152a6ebc-9465-47f5-8ee2-646ba6f51de2</guid><dc:creator>rajesh pamisetty</dc:creator><description>Thanks for the input,i have tried it earlier but an getting the following error&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Interface Definition: Expression evaluation error: An error occurred while executing a save: java.lang.IllegalStateException: A Value should not be the result of activation&lt;br /&gt;
&lt;br /&gt;
Can any one help me how to handle it?&lt;br /&gt;
&lt;br /&gt;
Thanks in advance&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/64652?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 10:34:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7612d958-85a2-4643-a5df-dad703bfb483</guid><dc:creator>jaisym</dc:creator><description>You can use foreach to save something in loop&lt;br /&gt;
a!buttonWidget(&lt;br /&gt;
label: &amp;quot;complete task&amp;quot;,&lt;br /&gt;
saveInto: {&lt;br /&gt;
/* how to write the below function in loop and how to save it using a!save function*/&lt;br /&gt;
a!save(local!task,a!forEach(items:ri!selectedTaskIDs,expression:a!completeTask(&lt;br /&gt;
taskId: tointeger(fv!item ),&lt;br /&gt;
taskInputs: { input: ri!taskInput },&lt;br /&gt;
onSuccess: a!save(ri!message, &amp;quot;Updated Successfully&amp;quot;),&lt;br /&gt;
onError: a!save(ri!message, &amp;quot;Already Updated&amp;quot;)&lt;br /&gt;
)&lt;br /&gt;
)&lt;br /&gt;
)&lt;br /&gt;
},&lt;br /&gt;
style: &amp;quot;PRIMARY&amp;quot;&lt;br /&gt;
)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/64579?ContentTypeID=1</link><pubDate>Tue, 12 Feb 2019 03:33:47 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5251feb9-acb2-4f98-b3f6-47deacdd0810</guid><dc:creator>rajesh pamisetty</dc:creator><description>a!buttonWidget(&lt;br /&gt;
                          label: &amp;quot;complete task&amp;quot;,&lt;br /&gt;
                          saveInto: {&lt;br /&gt;
                      /* how to write the below function in loop and how to save it using a!save function*/&lt;br /&gt;
                            a!completeTask(&lt;br /&gt;
                              taskId: tointeger(ri!selectedTaskIDs ),&lt;br /&gt;
                              taskInputs: { input: ri!taskInput },&lt;br /&gt;
                              onSuccess:  a!save(ri!message, &amp;quot;Updated Successfully&amp;quot;),&lt;br /&gt;
                              onError: a!save(ri!message, &amp;quot;Already Updated&amp;quot;)&lt;br /&gt;
                            )&lt;br /&gt;
                          },&lt;br /&gt;
                          style: &amp;quot;PRIMARY&amp;quot;&lt;br /&gt;
                        )&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to loop a!completeTask function and save the result</title><link>https://community.appian.com/thread/64564?ContentTypeID=1</link><pubDate>Mon, 11 Feb 2019 13:21:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a4d2a965-5116-43c7-a1b0-3b533aa9f87d</guid><dc:creator>Kenneth Chen</dc:creator><description>Can you elaborate more on the exact problem you&amp;#39;re facing when you&amp;#39;re trying the loop? (Maybe with code snippets?) I&amp;#39;m guessing your problem is that you&amp;#39;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.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>