How to return a Human Task Assignee Name/Id

I am new to Bonita and have tried my hands on some examples. I certainly have learned quite a lot from this community.

Please I need a guide on a script or expression to return an actor assigned to a current task in my process. The idea is to ensure that only this actor (group, role or user) is able to access the task within my Bonita app page.

 

Best regards,

Henry.

Hello,

If you use a script connector on a human task, one of the variables you directly have access to within the editor is taskAssigneeId. 

Hello Henry,

In your live application page, I imagine that already you had retrieved the task list for a process. I suppose that the task list is stored in a variable called taskList. Now, you Can:

  • Filter the list on the table (as you suggested)
  • display the selected task link only for authorized users.

In both cases you have to add a variable, external API, call it loggedUser, defined in this way:

../API/system/session/1

Now if you want to filter directly the taskList, in the table content property you write:

taskList|filter{assigned_id:loggedUser.user_id}

In this way you will have the table with the list of Task assigned to that user.

For the second case, if you don't want to filter the table, You can display only the task link of the selected task from the table to the correct user. If the selected case from table is called "selectedTask", In the Hidden property of the link you can write:

!(selectedTask.assigned_id == loggedUser.user_id)

Best regards,

Massimiliano

Thanks for your help.

Please as a newbie, I have successfully built my custom Travel Request App but want to restrict users from trying to execute certain tasks, by hiding the page Link widget.

So, below is what I want to achieve:

The Link widget that launches the approver form should only be visible to the actor (Group, Role, User) assigned the Human Task in Bonita. This means that the Link property (Hidden) should remain hidden except when the assignee actor is logged in.

Please help me with a detailed approach to achieve this as I am barely a month on the exciting world of Bonita.

Best regards,

On another thought...

If I can put a filter on my page table widget to return only records that each user is permitted to see and/or process, my problem will be over.

Than you again.

Thanks, Massimiliano for the very useful information to resolve my issues however, I am not getting the designed results in each scenario.

Sceanrio 1 (Table Filter):   

1. I added the loggedUser variable as ExternalAPI

2. I applied this code on the Content field: 

taskFromRequest|filter{assigned_id:loggedUser.user_id} 

where taskFromRequest is an External API  ../API/bpm/humanTask?c=1&p=0&f=caseId={{request.caseId}}

Result is an Empty Table. Please note that the table displays some data from BDM referenced by an External API ../API/bdm/businessData/com.company.model.TravelRequest?q=find&p=0&c=100

 

Scenario 2 (Link Hide from unassigned users):

1. I added !(request.assigned_id == loggedUser.user_id) to the Hidden field. Where request is my selected row on the table. Meanwhile, (request.assigned_id == loggedUser.user_id) makes the Link visible to all users.

Result: The Link is hidden from all users.

 

Honestly, I am not sure where I am missing something. Kindly help me out still. I wish I could find a way to upload screenshots here for better explanations.

 

Best regards,

Henry.

Dear Henry,

Now It's quite more clear, would be nice to see details about used BDM to better understand. Are You following some example as basis?

By the way, It seems that your BDM TravelRequest contain a field called caseId. Probabily you save the caseId on BDM, good choice. When You call humanTask in this way, you have already the information of the assignee on taskFromRequest[0].assigned_id. (I assume here that thask is already assigned). So now you have to compare this with the userId of the logged user to hide the link:

hidden:

!(taskFromRequest[0].assigned_id == loggedUser.user_id)

This will hide the link for everyone except the task assignee.. First scenario here don't apply because in the table here You aren't showing tasks, but the BDM data. Let me know.

Hey Massimiliano, You are good!

Actually, I am new (less than 2 months) to Bonita though I have tried another product in the past. I have read the official documentation and followed a couple of examples too. This work is my test which is close to a process in the company where I work now. I designed the process and now implementing it in Bonita.

1. The hiding of the Link widget from unassigned users works great now. I can't thank you enough!

2. Table displaying user tasks only: The ideal thing is for the users to see their associated tasks on the page table widget. Please help me on how to populate the table widget with user-specific tasks instead of BDM data as currently displayed.

 

Note: I am not sure how to export my BDM object to share here however, I added to the table caseId, creationDate, createdBy, completionDate which are bpm stuffs I need within the process.

 

Best regards,

Henry.

Dear Henry,

Good that you solved your Problem. Would be nice at this point that You flag this as the Answer and upvote. ;-).

You can have a table with Tasks for that user. For example in my living application I put the personal page of each user with a list of pending human task (also from different processes they can access) assigned to them. You have to create taskList variable defined in this way:

../API/bpm/humanTask?p=0&c=20&f=assigned_id={{loggedUser.user_id}}

In this way You will have a list of task of that user. Now you can put this list on a table or on a repeater container. Each task in the taskList would be this JSON object:

[{"displayDescription":"Processo di Gestione Segnalazioni CS2019_0022 - Integrazione Segnalazione","executedBy":"0","rootContainerId":"23002","assigned_date":"2020-02-26 15:13:13.657","displayName":"CS2019_0022","executedBySubstitute":"0","dueDate":"","description":"","type":"USER_TASK","priority":"normal","actorId":"2106","processId":"6803669643293863931","caseId":"23002","name":"Integrazione","reached_state_date":"2020-02-26 15:13:18.317","rootCaseId":"23002","id":"480011","state":"ready","parentCaseId":"23002","last_update_date":"2020-02-26 15:13:18.317","assigned_id":"302"}]

As you can see, here In the process I have assigned a dinamic display name that help you understand better what are you dealing with. To assign dynamic display name, in Studio, in the human task General Tab, Portal, you can assign display description by script something like:

return "Process xxx " + yourBDM.yourSignificantID + " - Name of action / task that is useful"

Thank you again Massimiliano.

Firstly, please help me with how to flag issues as Answer, etc.

Secondly, I just created a sample page added to my app, following your steps but it is not returning task data. Below is the property setting:

Headers: Task Name, Display Name, Assigned Date, Executed By

Content: taskList

Column Keys: name, displayName, assigned_date, executedBy

taskList is External API as 

../API/bpm/humanTask?p=0&c=20&f=assigned_id={{loggedUser.user_id}}

 

Please what am I missing?

 

Best regards,

Henry.

Hi Henry, 

Really I don't know as flag question answered, never done before, Simply I had some anwer flagged. I think you can simply upvote by clicking on the up arrow on the left of the answer. To flag maybe there is another button/link.

By the way. Make sure that you are logged on the portal (sometimes your session expires an no data is received with API call. Make sure to push "portal" button on bonita studio). To test your API call unfiltered and see what is coming out from call, just type in a blank window the complete API call:

http://localhost:8080/bonita/API/system/session/1

To first retrieve your real user_id. Then, supposing that your user_id is 302, Call:

http://localhost:8080/bonita/API/bpm/humanTask?p=0&c=20&f=assigned_id=302

And see what object is given. If you are correctly logged (the first call is empty if session has expired) and the task are assigned, You'll see such task in the JSON obect. If you don't see nothing, these options are possible:

  • No task assigned to that user
  • The task is not assigned at all

To be sure at this point, see on the portal if the task is assigned. If not, you have to assign it. Or, if you want done automatically when the human task is reached, you have to use the actor filter in this way:

In the General-> Actor tab of the Lane where the task is, select an actor and then Set an actor filter choosing Single user template and then editing the script:

apiAccessor.identityAPI.getUserByUserName(yourBDM.yourAssigneeUserName).id

where yourBDM.yourAssigneeUserName should contain the user name at wich assign the task.

Hi massimiliano,

1. The actor setup is perfectly set up and tested for the process.

2. The URL calls you advised above return valid JSON records for the process

The challenge is that my new page does not return any data. Something may be wrong with my variable definition, just saying...

 

Best regards,

Henry.

Maybe some spelling problem. If you want, try to export page and send to me at massidonno [at] gmail.

Best regards,

Massimiliano

Thank you so much, Massimiliano for your availability and help!

The 2 scenarios work perfectly well now. I have learned quite a lot.

Best regards,