how to increment local variable in for each in expression rule

Certified Senior Developer

how can i set counter value after each iteration in forEach funtionin eg set counter = counter +1 or counter = 1 based on condition 

Let just say

I have 2 CDT

itemA:{1,2,3}

itemB{c,d,e,f,g,h}

and i have to generate resultant CDT itemZ: [{ guid:c, ac:1}  , { guid:d, ac:2} ,{ guid:e, ac:3} , { guid:f, ac:1} ,{ guid:g, ac:2} ,{ guid:h, ac:3}  ] 

In my expression rule I am iterating itemB using  foreach function

local!counter:0,

local!ItemZ :foreach(

items:itemB

expression :a!localVariable(

local!:counter: if(length(ItemA)>= local!counter, local!:counter +1, 1),

if(length(ItemA)>= local!counter,

{

type!ItemZ

(

guid:fv!item,

ac:ItemA[counter]

)

},

/*else case */

{} 

)

)

)

)

Issue is:  every iteration counter is set to 0 instead of previous value of counter. 

  Discussion posts and replies are publicly visible