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
  • 0
    Certified Senior Developer


    Edit: this was my approach but I recommend the one by Hrishikesh Dixit.

    a!localVariables(
        local!UserList : {touser("ABC"),touser("PQR"),touser("GHJ")},
        local!LoanApplicationList: /*insert her how you get your application CDT Array*/,
        a!forEach(
          items: local!loanApplicationList,
          expression :  a!localVariables(
              local!application: fv!Item,
              local!Index: fv!Index,
              a!forEach(
                items:reverse(enumerate(count(local!userList))+1),
                expression: 
                    if(
                        mod(local!Index/fv!item)=0,
                        updatedictionary(
                          dictionary: local!application,
                          fieldsAndValues: {
                            user: index(local!UserList,fv!Item,null)
                          }
                        ),,
                        {}
                    )
                )
            )
        )
    )

Reply
  • 0
    Certified Senior Developer


    Edit: this was my approach but I recommend the one by Hrishikesh Dixit.

    a!localVariables(
        local!UserList : {touser("ABC"),touser("PQR"),touser("GHJ")},
        local!LoanApplicationList: /*insert her how you get your application CDT Array*/,
        a!forEach(
          items: local!loanApplicationList,
          expression :  a!localVariables(
              local!application: fv!Item,
              local!Index: fv!Index,
              a!forEach(
                items:reverse(enumerate(count(local!userList))+1),
                expression: 
                    if(
                        mod(local!Index/fv!item)=0,
                        updatedictionary(
                          dictionary: local!application,
                          fieldsAndValues: {
                            user: index(local!UserList,fv!Item,null)
                          }
                        ),,
                        {}
                    )
                )
            )
        )
    )

Children
No Data