Need to Copy all ritm variables to SC_TASK when sc_task is created with the help of Business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 01:52 AM
Hi
I need to copy the RITM variables in SCTASK variables while creating SCTASK via business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 02:38 AM
hi @mtonge ,
can you try something like below script is create on RITM table if you want to change then please modify the script accordingly
var taskID= createTask(); // create SCTASK
if(taskID){
var vars = new GlideRecord("item_option_new");
vars.addQuery('cat_item', current.cat_item); //bring variables
vars.query();
while (vars.next()) {
insertVariable(vars.sys_id,taskID);
}
}
function insertVariable(id,taskIDs) {
var gr = new GlideRecord('sc_item_variables_task');
gr.initialize();
gr.setValue('task', taskIDs);
gr.setValue('variable', id);
gr.insert();
}
function createTask(){
var sctask = new GlideRecord("sc_task");
sctask.initialize();
sctask.request_item = current.sys_id;
sctask.cat_item = current.cat_item;
var ids = sctask.insert();
return ids;
}
if my response helped you to solve the issue. Please mark my answer as accepted solution and give a thumb up
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2025 03:01 AM
Variables are stored in RITM level and just displayed in catalog task
I didn't get your requirement. why to copy?
Simply when you create catalog task and during creation you can specify which all variables are to be seen
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader