Loop to get the manager details

How to achieve this functionality ?

If user's manager band is between 0 to 3 then consider manager details of that user,
if user manager is more than 3 then manager's manager(next linemanager) band should be checked and if it is not between 0 to 3 then again check for next further line manager.
This process should be repeated until we get the any of the manager band as between 0,1,2,3.

  Discussion posts and replies are publicly visible

Parents
  • This is a great case for a small recursive function that calls itself until it finds the data "bands" you are looking for.

    In this example we take a User input and check for a title containing "VICE PRESIDENT", if it is found return the current user, if not, call itself with the manager of the user to loop until we find a Vice President.  You would need light updates such as swapping in your "band" information in line 3 and returning the manager in line 7 instead.

    Note when testing recursive functions, you MUST SAVE any code changes before testing the rule, or the current changes will be calling the previously saved version of the rule (and you will bang your head on debugging).  Additionally, make sure you have the proper code checks in place to prevent any situation that would allow the rule to infinitely run (such as the maximum call number check) - otherwise this can cause a major performance degradation of the server.  This rule has a setting of 10 for a maximum run count.

    rule!test_recur_getUser(user):

    if(
      or(
        search("VICE PRESIDENT",user(ri!user,"titleName"),1)>0, /* Search user title for VICE PRESIDENT */
        ri!callNumber>=10, /* set a max for safety! */
      ),
      /* Title found (or max loop hit), return user! */
      ri!user, 
      /* Call self recursively with user's supervisor */
      rule!test_recur_getUser(
        user: user(ri!user,"supervisorName"),
        callNumber: if(rule!APN_isEmpty(ri!callNumber),2,ri!callNumber+1)
      ) 
    )

Reply Children
No Data