Need to Copy all ritm variables to SC_TASK when sc_task is created with the help of Business rule

mtonge
Tera Contributor

Hi 

 

I need to copy the RITM variables in SCTASK variables while creating SCTASK via business rule. 

2 REPLIES 2

Bhavya11
Kilo Patron

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

Ankur Bawiskar
Tera Patron
Tera Patron

@mtonge 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader