JavaScript workflow for round-robin assignment with agent absence
As previously mentioned in another topic, I need to write a JavaScript workflow to support round-robin assignment on a rotating basis (not just least workload as in the public example) and incorporate agent absence due to holidays.
I have set up a HelpDesk project “HDP”. It has a custom “Query Type” field and a “Queue” field of type “group”. I have created groups of agents corresponding to the queues.
I have created a standard (graphical) workflow on ticket creation to set the Queue field appropriately based on the Query Type. This workflow also sets a tag, “toAssign”, which will trigger the JavaScript workflow.
I have set up two ancillary projects.
1. Queue (QUE), with three fields: “Queue” of type group, “Escalation” of type group, and “lastAssignee” of type user
2. Work Schedule Exception (WSE) with three fields: “Assignee” of type user, “Start” of type “Date and Time”, and “End” of type “Date and Time”.
The JavaScript workflow basically needs to do the following.
1. Look up the QUE issue corresponding to the HDP ticket's Queue field setting
2. Access the “lastAssignee” value
3. Increment that value, rolling back around to (0? 1?) if necessary
4. Check the prospective assignee user correponding to the incremented user value for open WSE issues assigned to them
5. If any WSE issue defines a datetime range which includes the current datetime, skip this user and try the next
6. In case all users in a queue are absent, access the QUE issue representing the group specified by the Escalation field and try to round-robin assign to it
7. In case there is no escalation group, we're at the top level already so just assign to the next user regardless of WSE
8. Remove the “toAssign” tag from the HDP issue
9. Store the new lastAssignee value on the QUE.
Is this something JetBrains might be able to help me with? It is rather complicated, from my perspective.
Please sign in to leave a comment.
I realized it made more sense for the QUE issues to have an Escalation field of type group, specifying the group (and QUE) to escalate to in case all group members generate a schedule exception.
Hello G. K.
In YouTrack Support, we're always glad to help with any questions about YouTrack or troubleshoot technical issues you might encounter, but designing workflows from a list of requirements is outside our scope.
We have a comprehensive JS Workflow reference documentation in our dev portal, which will help you design a desired workflow from scratch or using one of our default workflows as a jumping-off point: https://www.jetbrains.com/help/youtrack/devportal/Workflows-in-JavaScript.html.
If you need custom workflows built specifically for your team's use cases, please reach out to one of our consulting partners: https://www.jetbrains.com/company/consulting-partners/
Don't hesitate to reach out anytime if any questions arise. Have a great day!
Thanks, I completely understand. Maybe I can start with some simple questions, at least to get started.
In my ‘guard’, should I return just issue.isChanged("tags") or is it possible to return on the addition of a specific tag in that location?
Actually, I decided against using tags. I decided it would make more sense to trigger on the setting of the Queue field (which was previously set by the simple workflow based on the case type).
I define my Assignee and Queue fields in the Requirements section.
However, when I try to access these to write a console message, I get undefined.
Instead, I have to access them via ctx.issue.fields, then it works.
Is it supposed to work the first way?
Also, when I try to access properties of the group specified in the Queue field, they're undefined:
Can you give me some hint what I'm doing wrong?
Actually, never mind all this, I'm slowly making progress.