- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2020 08:50 PM
I am trying to populate a catalog task that is generated from the workflow with the same assignment group of the previously closed task like the below screenshot.
The SCTASK0045000 is closed with a Assignment group - "Asset" then the next catalog task SCTASK0045037 that generates should automatically have the assignment group from the previously generated task - Asset.
The newly generated task should populate with the previous task assignment group.
I am not getting an idea on the approach, could someone help me with this.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 11:49 PM
Hi
Thanks for your trust in me. In this case, I took some extra time to drill out the tested and working solution just for you 🙂
The script I supplied for you above was untested and was a scaffolding in fact - so sorry, if it threw an error. The below script is well tested, and all my tests succeeded to what you are telling me. I created an example workflow to test it.
Here is the new script, which I tested (and I hope it works for you as well):
Note: If intentionally left in all of my comments I took during testing, so it can also act as some sort of lesson for you, as well.
// The next line can be uncommented to review the current value on the Scratchpad
// gs.info('Dirk-BEFORE:' + workflow.scratchpad.pre_task_sysid);
// Only update/set the Assignment Group, if there was a previous SC_TASK
// which means, that the scratchpad variable was set before
if (workflow.scratchpad.pre_task_sysid != '') {
// The next line can be uncommented to debug, that the scratchpad has a "sys_id" stored
// gs.info('Dirk: There is a previous SYS_ID on Scratchpad');
// Open the "PREVIOUS" SC_TASK to get the Assignment Group of that task
var grTask = new GlideRecord('sc_task');
grTask.addQuery('sys_id', workflow.scratchpad.pre_task_sysid);
grTask.query();
// If the record was found, then assigne that assignment group to the new
if (grTask.next()) {
// The next line can be uncommented to log, that the previous task was found
// gs.info('Dirk: Previous Task found!');
task.assignment_group = grTask.assignment_group;
}
}
// BEFORE calling "task.setNewGuid()", the field "task.sys_id" is EMPTY !!
// gs.info('Dirks Workflow sys_id of SC_TASK-1: ' + task.sys_id);
// This call does not return any value, as the "sys_id" of the "task" Record ist not set yet
// gs.info('Dirks Workflow sys_id of SC_TASK-2: ' + task.getUniqueValue());
// We can get the NEW "sys_id" of the "task", if we now call for one!
// Store the GUID of this SC_TASK for NEXT SC_TASK (for reference)
workflow.scratchpad.pre_task_sysid = '' + task.setNewGuid();
// For testing purposes, uncomment the following line to review this in the "System Log"
// gs.info('Dirk-AFTER:' + workflow.scratchpad.pre_task_sysid);
This was my test-workflow to find out if it works as expected. I made is look like the steps you have in your workflow:
In Action:
Closing the first task will create the next one, which will take the Assignement group from the previous one:
See, that the second task took the same Assignment group as the previous one:
Now, if I change the Assignment Group of the second task manually and close the second task:
The next task will take again the Assignment Group of the previous one:
So, from my understanding, it is exactly what you have been asking for. This should solve your requirement in detail.
I made the script above generic in that way, that you can just copy it in EACH "Catalog Task" Activity Script in your workflow. That's escactly what I did. SO, you do not need to care about "the first task" and "the next task" conditions - or something like that.
Just copy in the script in have fun.
Let me know if that answers your question and mark my answer as correct and helpful.
BR
Dirk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2020 09:57 PM
Hi
I like the idea of Akshata, by searching for any "closed complete" state catalog Tasks, and update them.
But instead of distributing the logic through Workflow and Business Rule, I would try to keep the logic in one place: in the workflow. Because maybe, the idea of setting the "next" SC_TASK to the same assignment group will only be valid for this ONE Workflow, but not for others. In this case, the Business Rule will also change/set the Assignment Group as well. This may be undesired.
My proposal is, to do something similar in the Workflow:
In each "Create Task" Workflow Activity check the "Advanced" Option and add the following lines of code to the script:
// Only update/set the Assignment Group, if there was a previous SC_TASK
// which means, that the scratchpad variable was set before
if (workflow.scratchpad.pre_task_sysid) {
// Open the "PREVIOUS" SC_TASK to get the Assignment Group of that task
var grTask = new GlideRecord('sc_task');
grTask.addQuery('sys_id', workflow.scratchpad.pre_task_sysid);
// If the record was found, then assigne that assignment group to the new
if (grTask.next()) {
task.assignment_group = grTask.assignment_group;
}
}
// Store the GUID of this SC_TASK for NEXT SC_TASK (for reference)
workflow.scratchpad.pre_task_sysid = setNewGuid();
This will store the Sys_ID of the task on the scratchpad (at the end of the script)
In the beginning, it checks, if the scratchpad already was set by a previous task.
If yes, it searches for that task, and if found, will update the current one with the assignment group form the previous. Afterwards, the current sysid is stored again to the scratchpad.
Let me know if that answers your question and mark my question as correct and helpful.
BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 08:28 AM
Hi Dirk,
I could be doing something wrong from my end, but I have copied your script above by clicking on the advanced and getting an error.
There is a routing for the first task based on location and department and the next task is generated when the first task is closed.
The next task that generates lets say, "Prepare Items for Delivery to Customer" should pick the assignment group of the previous task i.e. Pick up purchased items from Warehouse.
Even though the first task is routed based some routing rules, it could be changed by the agent working on that task so the assignment group should be carried over to the 2nd task.
I was interested in this approach because this is something new I am learning and did know we could do it here at the workflow level and the script you have.
I really appreciate your help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 11:49 PM
Hi
Thanks for your trust in me. In this case, I took some extra time to drill out the tested and working solution just for you 🙂
The script I supplied for you above was untested and was a scaffolding in fact - so sorry, if it threw an error. The below script is well tested, and all my tests succeeded to what you are telling me. I created an example workflow to test it.
Here is the new script, which I tested (and I hope it works for you as well):
Note: If intentionally left in all of my comments I took during testing, so it can also act as some sort of lesson for you, as well.
// The next line can be uncommented to review the current value on the Scratchpad
// gs.info('Dirk-BEFORE:' + workflow.scratchpad.pre_task_sysid);
// Only update/set the Assignment Group, if there was a previous SC_TASK
// which means, that the scratchpad variable was set before
if (workflow.scratchpad.pre_task_sysid != '') {
// The next line can be uncommented to debug, that the scratchpad has a "sys_id" stored
// gs.info('Dirk: There is a previous SYS_ID on Scratchpad');
// Open the "PREVIOUS" SC_TASK to get the Assignment Group of that task
var grTask = new GlideRecord('sc_task');
grTask.addQuery('sys_id', workflow.scratchpad.pre_task_sysid);
grTask.query();
// If the record was found, then assigne that assignment group to the new
if (grTask.next()) {
// The next line can be uncommented to log, that the previous task was found
// gs.info('Dirk: Previous Task found!');
task.assignment_group = grTask.assignment_group;
}
}
// BEFORE calling "task.setNewGuid()", the field "task.sys_id" is EMPTY !!
// gs.info('Dirks Workflow sys_id of SC_TASK-1: ' + task.sys_id);
// This call does not return any value, as the "sys_id" of the "task" Record ist not set yet
// gs.info('Dirks Workflow sys_id of SC_TASK-2: ' + task.getUniqueValue());
// We can get the NEW "sys_id" of the "task", if we now call for one!
// Store the GUID of this SC_TASK for NEXT SC_TASK (for reference)
workflow.scratchpad.pre_task_sysid = '' + task.setNewGuid();
// For testing purposes, uncomment the following line to review this in the "System Log"
// gs.info('Dirk-AFTER:' + workflow.scratchpad.pre_task_sysid);
This was my test-workflow to find out if it works as expected. I made is look like the steps you have in your workflow:
In Action:
Closing the first task will create the next one, which will take the Assignement group from the previous one:
See, that the second task took the same Assignment group as the previous one:
Now, if I change the Assignment Group of the second task manually and close the second task:
The next task will take again the Assignment Group of the previous one:
So, from my understanding, it is exactly what you have been asking for. This should solve your requirement in detail.
I made the script above generic in that way, that you can just copy it in EACH "Catalog Task" Activity Script in your workflow. That's escactly what I did. SO, you do not need to care about "the first task" and "the next task" conditions - or something like that.
Just copy in the script in have fun.
Let me know if that answers your question and mark my answer as correct and helpful.
BR
Dirk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 02:17 PM
Hi
Did my solution work for you and solve the problem?
Let me know if that answered your question and mark my answer as correct and helpful.
BR Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2020 01:02 PM
Hi Dirk,
Yes, I was able to use your code for a different workflow.
I have marked your reply helpful already 🙂
Thank you for showing this to me, I would have never thought of this. I got to learn something new.