foreach update another counter

Hi there,

I have a list of applications (n) which have to be equally distributed amongst users (n). Say there are 10 applications and 3 users where application is a CDT and I am using updatedictnary () for setting application.user : user1. Distribution should be like --> 

application 1 : user 1

application 2 : user 2

application 3 : user 3

application 4 : user 1

application 5 : user 2

application 6 : user 3

application 7 : user 1

application 8 : user 2

application 9 : user 3

application 1 : user 1

How can this be achieved using only foreach? or is there any better way to do it?  Something I tried 

local!i:1,
local!UserList : {touser("ABC"),touser("PQR"),touser("GHJ")},
local!UserCount : count(local!UserList),
a!forEach(
  items: local!LoanApplicationList,
  expression :  
    updatedictionary(
      dictionary: fv!item,
      fieldsAndValues: {
        ApplicationUser :
        if(local!i=local!ListTotalUserCount,
          {
            local!i:sum(local!i,1),
           tostring(ri!UserList[local!i])            
          },
          tostring(ri!UserList[local!i])            
          )
      }
    )
)

Thanks in advance,

Sweta

  Discussion posts and replies are publicly visible

Parents
  • /*Following code should work for (n) applications/users*/
    a!localVariables(
      local!users: {"aaa", "bbb", "ccc"}, /*set your users here*/
      local!applications: {}, /* insert/initialize your application CDT here */
      local!countOfUsers: count(local!users),
      a!forEach(
        items: local!applications,
        expression: {
          updatecdt(
            fv!item,
            {
              user: index(
                local!users, 
                if(
                  fv!index > local!countOfUsers, 
                  if(mod(fv!index, local!countOfUsers) = 0, local!countOfUsers, mod(fv!index, local!countOfUsers)), 
                  fv!index
                ), 
                ""
              )
            }
          )
        }
      )
    )

Reply
  • /*Following code should work for (n) applications/users*/
    a!localVariables(
      local!users: {"aaa", "bbb", "ccc"}, /*set your users here*/
      local!applications: {}, /* insert/initialize your application CDT here */
      local!countOfUsers: count(local!users),
      a!forEach(
        items: local!applications,
        expression: {
          updatecdt(
            fv!item,
            {
              user: index(
                local!users, 
                if(
                  fv!index > local!countOfUsers, 
                  if(mod(fv!index, local!countOfUsers) = 0, local!countOfUsers, mod(fv!index, local!countOfUsers)), 
                  fv!index
                ), 
                ""
              )
            }
          )
        }
      )
    )

Children