Is there a way to run a Script within a workflow and make tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 11:43 AM
Hello, I have a complex problem I'm trying to solve, is there a way to run a Script within a workflow and make tasks based on how many Roles are within a group, for example as an end user I'm trying to select a group I'm trying to get in and based off the Roles, those should create individual tasks to be approved. so, if I choose a group and there's 3 roles within that group, 3 Tasks should be made automatically to be approved by someone. Same as if there was 5, there should be 5 so on and so forth,
Any help is appreciated, thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 12:34 PM
Hi @HenryD yes, you can use Run Script activity https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/administer/workflow-activit...
Regards,
Siddharam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:24 PM - edited 02-09-2024 01:36 PM
Hi @HenryD,
Sure, technically possible with adding Run Script object within the workflow, the script can be coded with required logic to fetch the roles from selected group and create the no. of catalog task, however the next challenge will start from this point because those tasks independent and no linkage with running workflow context ( however Task will be associated with RITM) but once task is closed (or cancelled), workflow will not get any trigger point for next action. [ this can be manage via additional BR on sc_task for specific catalog item, this will add more complexity for that catalog item ]
The same is applied to approvals [ which is on RITMs ], in ideal situation, we applied the Approval User or Approval Group before the Catalog Task object and there is no task object here as tasks are created via Run Script.
and how the roles are mapped with some approval users or groups , role are independent items no one owns it, that's the reason ServiceNow has group feature and group has manger, so manager's approval should be enough for any request approval ( or additional hierarchical approval or specific user/team approval ).
Let's see, if you have role and role manager mapping, then you can manage to add approval at RITM level and once all approvals are approved then you can create single task ( or more ). Separate the approval part from task.
My Suggestion: Let's see role base approval are mandatory at RITM level and we dont need the N number of Catalog Task.
1) Create a new group for this catalog item. ( like : Manager Of Roles )
2) In workflow, read the no. of role from selected group and add those mapped approver in this new group.
3) Apply the Approval Group object in workflow (every one has to approve) [ this will work for N no of approvers]
4) Add the catalog task(s) after the approval object, and add required logic ( as needed ) till End object.
5) Remove the role managers from this group before the End object in workflow. [ Risk : When more requests opens at the same time, this group will have more roleManagers ]
Let me know if you have any query.
Note: Please excuse if any typo.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 11:54 AM
Hello, yes this does sound like what i want, do you know what the script would look like? im having trouble figuring out the best way to grab the roles then populate the tasks based off how many roles are in a group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 02:01 PM
Hi @HenryD .
Ideally most of org have group based approval because group has manager.
Options 1
First of all you have to determine the role & role manger mapping , means ServiceNow instance must have a table with at least two column ( or more as required )
1) Role ( Reference to Role Table ) and
2) Role Manager ( Reference to User table )
3) Active ( or IsDeleted ) Boolean ( Optional, better to have )
Option 2
Or , you can add a new column ( Let's say it Role Manager : Reference to User table ) in existing Role [ sys_user_role ] table [ Note: This is considered foundation data , not recommended to change/update ]
-- at this stage role & role manager mapping is confirm [ i will go with option 1 ]
-- now, as we have group from catalog item and that group already has some role
-- in workflow, we can fetch the role manager's of selected group and using "Advance" section script we can push the manager's userid in answer.push() method with wait for "Every one has to approve".
Let me know if this helps, or i can walk through in call.
Note: Don't plan for N-number of task based on N-number of group role, instead plan for N-number of approval and one/more defined task(s).
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution