- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2025 10:15 AM
I am using the below script
But it is not working
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2025 10:34 AM - edited 06-17-2025 11:53 AM
Hello @SHALIKAS !
Your current script fails in this line: myVar.task = task.sys_id;
task is undefined in this context. You just inserted the new Catalog Task record into scGr, so you must reference scGr.sys_id (or store that value in a variable) before you loop.
Please try this code. I adjusted your code a bit and fixed some common issues without changing its scope.
// 1. Create the Catalog Task
var taskGR = new GlideRecord('sc_task');
taskGR.initialize();
taskGR.request_item = current.sys_id; // Link to RITM
taskGR.short_description = 'Task for Email All data collection';
taskGR.description = 'Task for Email All data collection. For the following Custodian: ';
var taskSysId = taskGR.insert(); // Commit & keep the sys_id
// 2. Pick the catalog variables you want to expose on the task
var varGR = new GlideRecord('item_option_new');
varGR.addQuery('cat_item', current.cat_item);
varGR.query();
// 3. Link each variable to the task
while (varGR.next()) {
var linkGR = new GlideRecord('sc_item_variables_task');
linkGR.initialize();
linkGR.task = taskSysId; // <-- FIXED
linkGR.variable = varGR.getUniqueValue(); // sys_id of item_option_new
linkGR.insert();
}
Please consider marking my answer as helpful and accepting it as the solution if it assisted you in any way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2025 10:34 AM - edited 06-17-2025 11:53 AM
Hello @SHALIKAS !
Your current script fails in this line: myVar.task = task.sys_id;
task is undefined in this context. You just inserted the new Catalog Task record into scGr, so you must reference scGr.sys_id (or store that value in a variable) before you loop.
Please try this code. I adjusted your code a bit and fixed some common issues without changing its scope.
// 1. Create the Catalog Task
var taskGR = new GlideRecord('sc_task');
taskGR.initialize();
taskGR.request_item = current.sys_id; // Link to RITM
taskGR.short_description = 'Task for Email All data collection';
taskGR.description = 'Task for Email All data collection. For the following Custodian: ';
var taskSysId = taskGR.insert(); // Commit & keep the sys_id
// 2. Pick the catalog variables you want to expose on the task
var varGR = new GlideRecord('item_option_new');
varGR.addQuery('cat_item', current.cat_item);
varGR.query();
// 3. Link each variable to the task
while (varGR.next()) {
var linkGR = new GlideRecord('sc_item_variables_task');
linkGR.initialize();
linkGR.task = taskSysId; // <-- FIXED
linkGR.variable = varGR.getUniqueValue(); // sys_id of item_option_new
linkGR.insert();
}
Please consider marking my answer as helpful and accepting it as the solution if it assisted you in any way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2025 10:39 AM
Hi @SHALIKAS First add variable editor on sc task form view.
later go to the flow or workflow which ever you are using.
if flow then open the catalog task action and scroll down there you see the variables in left slush bucket add them to right side then it will show on task form view.
if workflow then open the catalog task activity and scroll down there you see the variables in left slush bucket add them to right side then it will show on task form view.
you need to perform this for each task.
Thanks
Prashanth
Please mark the answer correct & Helpful, if i could help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2025 10:43 AM
Hi @SHALIKAS
there are few way you can achieve this
1. use normal catalog task activity and add all the variables to the list collector
2. check the global checkbox in the variables
these will display the variables on the sc_task form
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya