BPM, Workflow, and Case

BPM, Workflow, and Case

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
Expand all | Collapse all

tw.system.org.createRole returns null instead of a TWRole object

  • 1.  tw.system.org.createRole returns null instead of a TWRole object

    Posted Wed July 10, 2024 09:45 AM

    Hi All,

    We need to reassign tasks to a new list of users outside of the application, knowing the new user list, and the task ID. Now we use the task.reassignTo method, passing the list of user names, but it changes the display name of the group from the original to "Temporary group" or something like this on the Process Portal.

    As we know, the task.reassignTo method accepts a TWUser or a TWRole object, so we want to create a TWRole object, set the properties - name property too - and call the reassignTo method. But the tw.system.org.createRole method do not create and return a valid TWRole object, it returns always null.

    So, how to reassign a task to a list of users using an API function without modifying the original display name of the group of users on the Process Portal under the task?

    Thx,



    ------------------------------
    Laszlo
    ------------------------------


  • 2.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Wed July 10, 2024 10:14 AM

    Hi Laszlo,

    tw.system.org.createRole does not return anything. You can use this API to create the role, then find the role and add users like - 

    tw.system.org.findRoleByName("ROLE_NAME").addUsers("USER");

    Thanks!



    ------------------------------
    Atanu Roy
    Lead Engineer
    London Stock Exchange Group
    ------------------------------



  • 3.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Wed July 10, 2024 10:33 AM

    We don't know the role name or sometimes we need to reassign from a user to a group



    ------------------------------
    Laszlo
    ------------------------------



  • 4.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Wed July 10, 2024 12:26 PM

    Hi Atanu,

    When we get the actual role name of a task assignment using tw.system.findTaskByID(216068).assignedTo.name, we get a crix-crax like this: l3SWFkdAIxZRQnp9Sj2tWVF6us5IdenFdc9Ya3i0eLY= (16725). What a hell is it? Process Inspector writes this for the task: The task is assigned to TDM Document managers and coordinators

    Thx,



    ------------------------------
    Laszlo
    ------------------------------



  • 5.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Wed July 10, 2024 01:38 PM

    Hi Atanu,

    I tried to remove or add users to the role assigned to a task, but it failed:
    CWLLG3237E: Users and groups can neither be added nor deleted from an ad hoc group.

    So it seems that I can read the displayName (not documented here: JavaScript API in processes and service flows - IBM Documentation) and users of a role, but can't modify user list, can't create a new TWRole object (createRole returns null), can't create a new TWTeam (TWTeam is not instantiable). task.assignTo accepts TWUser, TWRole and TWTeam, but simply can't create a new object with these classes. It's crazy... 

    Any other idea to either replace the users of the current role assigned to a task or to create a new role object?

    thx 



    ------------------------------
    Laszlo
    ------------------------------



  • 6.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 12:04 AM

    Hi Laszlo,

    It is not good to provide the technical solution without asking the business problem, sorry I didn't ask you before.

    Can you please explain what are you trying to achieve? What is the current implementation etc. ?

    To answer your questions - 

    1. l3SWFkdAIxZRQnp9Sj2tWVF6us5IdenFdc9Ya3i0eLY= (16725) is a dynamic/ad-hoc group created at runtime, you can check the members of this group from REST API Tester->Organization API->Group Details.
    2. Yes, system created ad-hoc groups cannot be modified, but what you can do -
      1. Retrieve the users from that group
      2. Create a new role using JS API
      3. Assign the new set of users to the new role
      4. Reassign the task to the new role.

    Thanks!



    ------------------------------
    Atanu Roy
    Lead Engineer
    London Stock Exchange Group
    ------------------------------



  • 7.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 02:32 AM
    Edited by Laszlo Kertesz Thu July 11, 2024 04:25 AM

    Hi Atanu,

    It is an independent application which detects if somebody is on holiday and reassigns his/her tasks to the substitute person. When the task is assigned to a group of users, it checks for all te users in the group.

    "Create a new role using JS API"

    The problem is that we cannot create a new role because createRole do not returns a valid TWRole object, and TWRole, TWTeam is not instantiable [cannot instantiate object error comes when we try this: var x = new TWRole() or var x = new TWTeam()]. So we simply can't create any object (TWRole or TWTeam) which is accepted by the task.reassignTo method. The only way is when we pass the list of users to this method, but is this case the display name of the group is missing and it is a big problem for the customer.

    Thx,



    ------------------------------
    Laszlo
    ------------------------------



  • 8.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 02:49 AM

    Hi Laszlo,

    Understood the problem but still not getting why are you trying to all those complex calculations. There can be three scenarios with a task- 

    1. Claimed by a user who is part of a certain group and goes on holiday without completing the task
      • I think you are trying to solve this scenario, if that is the case, then why don't you simply assign the task back to the original group (using reassignBackToRole() )?
    2. The task is assigned to a group and a user of that group goes on holiday
      • No action is required, any other user of the group can claim the task an work on.
    3. Very rare case: The task is assigned to a group which is having only one user and that user goes on holiday
      • In this case, you can assign the task to some other team who used to deal with the exception scenarios.
      • You should always setup a team if you think this type of situation can happen.

    Can you please elaborate why you need all those role creation and assignment ?

    Thanks!



    ------------------------------
    Atanu Roy
    Lead Engineer
    London Stock Exchange Group
    ------------------------------



  • 9.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 03:16 AM

    Hi Atanu,

    1. Claimed by a user who is part of a certain group and goes on holiday without completing the task
      • I think you are trying to solve this scenario, if that is the case, then why don't you simply assign the task back to the original group (using reassignBackToRole() )?

    Because we must reassign to the substitute of the given user, and any other member of the original group may be on holiday in which case we must reassign to his/her substitute.

    1. The task is assigned to a group and a user of that group goes on holiday
      • No action is required, any other user of the group can claim the task an work on.

    We must reassign to the substitute of the given user, even when other users are in the group.

    1. Very rare case: The task is assigned to a group which is having only one user and that user goes on holiday
      • In this case, you can assign the task to some other team who used to deal with the exception scenarios.

    No, I can not assign to another team because I can't instantiate TWRole or TWTeam object to pass to the reassignTo method.

      • You should always setup a team if you think this type of situation can happen.

    Not valid business scenario. We must always assign the task to the substitute (or to the subsitute of the substitute and so on in the substitution tree of a user; if no subsitute present, then a reassigning task to the boss (or replacement of the boss) of the user.

    I appreciate your solutions but the only way is to create a new group of users keeping the original display name. And this is the problem: we cannot instantiate a TWRole or a TWTeam object, and this is crazy. IBM created a method to instatiate a TWRole object (createRole), but this never intantiate a TWRole object, even returns always null. This is crazy again. Unbelieveable.

    Thx,



    ------------------------------
    Laszlo
    ------------------------------



  • 10.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 05:10 AM

    Hi Laszlo,

    Thanks for the explaining the scenario, as I mentioned in the second answer, you should follow below steps - 

    var now = new TWDate();
    var task = tw.system.findTaskByID(<TK_ID>);
    var roleName = task.assignedTo.name+"_"+now.format("ddMMyyyyHHmmssSSS");
    tw.system.org.createRole(roleName, task.assignedTo.displayName, "SOME_DESCRIPTION", false);
    var role = tw.system.org.findRoleByName(roleName);
    role.addUsers(["USR1", "USR2"]);
    task.reassignTo(role);

    Do the necessary null and for the role name length checks before role creation. You can have your own logic to make the role name unique.

    Hope this helps. 



    ------------------------------
    Atanu Roy
    Lead Engineer
    London Stock Exchange Group
    ------------------------------



  • 11.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 05:17 AM

    Hi Atanu,

    I see, but createRole returns null always. It do not creates a role object. You wrote too.

    Thx



    ------------------------------
    Laszlo
    ------------------------------



  • 12.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 05:28 AM
    Edited by Atanu Roy Thu July 11, 2024 05:29 AM

    Hi Laszlo,

    Yes, it does, I just observed now, this is also working - 

    var now = new TWDate();
    var task = tw.system.findTaskByID(<TK_ID>);
    var roleName = task.assignedTo.name+"_"+now.format("ddMMyyyyHHmmssSSS");
    var role = tw.system.org.createRole(roleName, task.assignedTo.displayName, "SOME_DESCRIPTION", false);
    role.addUsers(["USR1", "USR2"]);
    task.reassignTo(role);

    I am using v22.0.1

    Thanks!



    ------------------------------
    Atanu Roy
    Lead Engineer
    London Stock Exchange Group
    ------------------------------



  • 13.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 05:34 AM

    Okay, I give it a try.

    Thx,



    ------------------------------
    Laszlo
    ------------------------------



  • 14.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 05:41 AM

    Okay, this is working. I don't know why I got null always. Maybe the role name was invalid, it do not accept a readable role name, just that crix-crax



    ------------------------------
    Laszlo
    ------------------------------



  • 15.  RE: tw.system.org.createRole returns null instead of a TWRole object

    Posted Thu July 11, 2024 05:42 AM

    Great! Finally it worked!



    ------------------------------
    Atanu Roy
    Lead Engineer
    London Stock Exchange Group
    ------------------------------