Skip to main content
January 5, 2021
Solved

how to increment local variable in for each loop in appian expression rule?

  • January 5, 2021
  • 2 replies
  • 0 views

i written code : 

with(
local!prioritylist:{1,2,3,4,5,6,7,8,9,10},
local!missinglist{}:{},
local!newmissing,
local!count:0,
local!temp: a!forEach(
items:local!prioritylist,
expression:
if(fv!item <ri!priority,if(rule!CRP_Checkdepartmentwisepriority(fv!item,ri!department)=0,append(local!missinglist{},fv!item),local!missinglist{}),local!missinglist{}),

local!newmissing:if(count(local!missinglist{})>0,count(local!missinglist{}),local!newmissing)
),


local!temp

)

i got the output like this:

List of Variant - 10 items

    • List of Variant - 0 items
      • List of Variant - 0 items
        • List of Number (Integer) - 1 item
            • 3(Number (Integer))
            • List of Variant - 0 items
              • List of Variant - 0 items
                • List of Variant - 0 items
                  • List of Variant - 0 items
                    • List of Variant - 0 items
                      • List of Variant - 0 items
                        • List of Variant - 0 items

                        Here i want sum of count of each list of this list . Answer should be 1

                        So, How to add the count of each list in one variable??

                          Best answer by mikes0011

                          I'm pretty confused as to what you're trying to do here, and/or what you expect the outcome to be.

                          You ask "how to increment a local variable in a for each loop" and the short answer is, really, "you don't", because that's not how the Appian expression language, or the a!forEach() function, work.

                          Also I'm confused by what you're doing with the local!newmissing variable that seems to be inside the a!forEach() expression section - this is not syntactically valid.  And again I'm unclear what it's intended to accomplish.

                          The expected output of the a!forEach() function is an array.  If, for example, you want the total result of the sum of all items in that array, you simply need to pass the result through the sum() function afterwards.  Like, sum(local!temp) etc.

                          2 replies

                          mikes0011
                          mikes0011Answer
                          Brainy
                          January 5, 2021

                          I'm pretty confused as to what you're trying to do here, and/or what you expect the outcome to be.

                          You ask "how to increment a local variable in a for each loop" and the short answer is, really, "you don't", because that's not how the Appian expression language, or the a!forEach() function, work.

                          Also I'm confused by what you're doing with the local!newmissing variable that seems to be inside the a!forEach() expression section - this is not syntactically valid.  And again I'm unclear what it's intended to accomplish.

                          The expected output of the a!forEach() function is an array.  If, for example, you want the total result of the sum of all items in that array, you simply need to pass the result through the sum() function afterwards.  Like, sum(local!temp) etc.

                          January 6, 2021

                          Thanks Mike. through sum(local!temp) I resolved my issue.