Need to create a task manually via Workflow under the RITM . I have RITM created but unable to add the catalog tasks underneath that in servicenow

collfit
Giga Contributor

Need to create a task manually via Workflow under the RITM . I have RITM created but unable to add the catalog tasks underneath that in servicenow 

 

find_real_file.png

 

 

var tsk = new GlideRecord('sc_task');

tsk.initialize();

tsk.request_item = current.sys_id;

tsk.state = 1;

 

task.insert();

 

Please let me know if any additions  needed or do we have any other process ?

 

 

1 ACCEPTED SOLUTION

There are syntax errors. I corrected them. try this.

 

var tsk = new GlideRecord('sc_task');
//test
tsk.initialize();

//tsk.u_access_requested_for = current.variables.u_term_name;

// tsk.due_date = current.due_date;
//tsk.description = reqItem.sys_id;
//tsk.request_item = reqItem.sys_id;

tsk.request_item = workflow.scratchpad.reqItem;

tsk.state = 1;
tsk.approval.setDisplayValue('Approved');
tsk.assignment_group = "sys_id of GRP"; 

tsk.insert();


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

13 REPLIES 13

While creating the ritm in the workflow, store the sysid of the new ritm in a scratchpad.

 

SO you ritm create script while inserting the ritm should be 

workflow.scratchpad.ritm = ritm.insert();   // Replace ritm with your glideobject you used while creating the ritm

 

And your tasks script  should be 

 

var tsk = new GlideRecord('sc_task');

tsk.initialize();

tsk.request_item = workflow.scratchpad.ritm;

tsk.state = 1;

task.insert();


Please mark this response as correct or helpful if it assisted you with your question.

collfit
Giga Contributor

Sorry for the confusion. 

What we are trying to accomplish here is the following

We understand you can create a task using the current.sys_id. However we are creating a new RITM within the workflow and we need the tasks new created to be under that new RITM. and since the current.sys_id will be the original RITM which is not the new one. We are wondering how we can link the new created Task with the new RITM created within the workflow

 

Thanks . 

collfit 

While creating the ritm in the workflow, store the sysid of the new ritm in a scratchpad.

 

SO you ritm create script while inserting the ritm should be 

workflow.scratchpad.ritm = ritm.insert();   // Replace ritm with your glideobject you used while creating the ritm

 

And your tasks script  should be 

 

var tsk = new GlideRecord('sc_task');

tsk.initialize();

tsk.request_item = workflow.scratchpad.ritm;

tsk.state = 1;

task.insert();

 


Please mark this response as correct or helpful if it assisted you with your question.

i tried this and it is not working i think .

The below code is to Create a separate RITM .  

var reqItem = new GlideRecord('sc_req_item');
reqItem.initialize();
reqItem.request = current.request.sys_id;
reqItem.assignment_group = "68c248484f0d4300f76d27201310c77f";
workflow.scratchpad.reqItem = reqItem.insert();

It created but did not assign a TASK to it . 

 

Below is the TASK code : 

 

var tsk = new GlideRecord('sc_task');
//test
tsk.initialize();

//tsk.u_access_requested_for = current.variables.u_term_name;

// tsk.due_date = current.due_date;
//tsk.description = reqItem.sys_id;
//tsk.request_item = reqItem.sys_id;

tsk.request_item = workflow.scratchpad.reqItem;/

tsk.state = 1;


task.approval.setDisplayValue('Approved');
task.assignment_group = "sys_id of GRP"; 

task.insert();

 

It is not inserting the task to the above RITM . 

 

Please help!

You need to change task to tsk for below code

 

task.approval.setDisplayValue('Approved');
task.assignment_group = "sys_id of GRP"; 

task.insert();