Workflow is not triggering when creating Request/RITM/TASK manually through Script Include. What variable/value should I set on RITM, so the workflow is triggered?

ket
Giga Contributor

This is creating Request, Request Item and Task. Request Item is binded to a Catalog Item. But not sure what to set in RITM (stage?? or anything else??), so that it will later trigger workflow. As currently I am closing the Task but it is not closing RITM or Request. When created Request/RITM/Task through same catalog item from portal it is working fine.

var task = new GlideRecord('sc_task');

task.initialize();

//Task

task.short_description = 'Task created manually';

task.assignment_group = '234b4edbdb771204b9e63bc0cf9619f9';

task.requested_for = 'gh4f6854db0a1200b9e63bc0cf9619b5';

task.opened_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';

task.u_requested_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';

task.u_requested_date = gs.nowDateTime();

task.description = 'Task created manually';

//Request Item

task.request_item.short_description = 'Task created manually';

task.request_item.stage = ??

task.request_item.request.short_description = 'Task created manually';

task.request_item.u_requested_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';

task.request_item.opened_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';

//Manual Creation Catalog Item.//Binding catalog item which has workflow assigned to it.

task.request_item.cat_item = '55a54ef413deb200fa7c73076144b0bf';

//Request

task.request_item.request.description = 'Task created manually';

task.request_item.request.requested_for = 'gh4f6854db0a1200b9e63bc0cf9619b5';

task.request_item.request.opened_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';

task.request_item.request.due_date = gs.nowDateTime();

task.insertWithReferences();

1 ACCEPTED SOLUTION

ket
Giga Contributor

I was able to achieve as below and now it is triggering workflow. When I close task it is closing RITM and Request.



var cart = new Cart();


var item = cart.addItem('49a54ef413deb200fa7c73076144b0bf');


cart.setVariable(item, 'recipient', 'gh4f6854db0a1200b9e63bc0cf9619b5');


cart.setVariable(item, 'opened_by', 'gh4f6854db0a1200b9e63bc0cf9619b5');


var rc = cart.placeOrder();


//Update Request


var req = new GlideRecord('sc_request');


req.addQuery('sys_id','=',rc.sys_id);


req.query();


if (req.next())


{


  req.opened_by= 'gh4f6854db0a1200b9e63bc0cf9619b5';


  req.requested_for = 'gh4f6854db0a1200b9e63bc0cf9619b5';


  req.description = 'Manual Request Creation';


  req.short_description = 'Manual Request Creation';


  req.update();


}


//Update Request Item


var reqitm = new GlideRecord("sc_req_item");


reqitm.addQuery('request','=',rc.sys_id);


reqitm.query();


if (reqitm.next())


{


  reqitm.opened_by= 'gh4f6854db0a1200b9e63bc0cf9619b5';


  reqitm.u_requested_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';


  reqitm.update();


}


//Update Task


var itm = new GlideRecord('sc_task');


itm.addQuery('request_item',reqitm.sys_id);


itm.query();


while(itm.next())


{


  itm.opened_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';


  itm.u_requested_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';


  itm.u_requested_date = gs.nowDateTime();


  itm.description = 'Manual Task Creation';


  itm.short_description = 'Manual Task Creation';


  itm.update();


}


View solution in original post

7 REPLIES 7

Hello Pradeep,



This code is just creating request. I am not sure why it is not creating RITM.


Hello Pradeep,



Can you please help?


ket
Giga Contributor

I was able to achieve as below and now it is triggering workflow. When I close task it is closing RITM and Request.



var cart = new Cart();


var item = cart.addItem('49a54ef413deb200fa7c73076144b0bf');


cart.setVariable(item, 'recipient', 'gh4f6854db0a1200b9e63bc0cf9619b5');


cart.setVariable(item, 'opened_by', 'gh4f6854db0a1200b9e63bc0cf9619b5');


var rc = cart.placeOrder();


//Update Request


var req = new GlideRecord('sc_request');


req.addQuery('sys_id','=',rc.sys_id);


req.query();


if (req.next())


{


  req.opened_by= 'gh4f6854db0a1200b9e63bc0cf9619b5';


  req.requested_for = 'gh4f6854db0a1200b9e63bc0cf9619b5';


  req.description = 'Manual Request Creation';


  req.short_description = 'Manual Request Creation';


  req.update();


}


//Update Request Item


var reqitm = new GlideRecord("sc_req_item");


reqitm.addQuery('request','=',rc.sys_id);


reqitm.query();


if (reqitm.next())


{


  reqitm.opened_by= 'gh4f6854db0a1200b9e63bc0cf9619b5';


  reqitm.u_requested_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';


  reqitm.update();


}


//Update Task


var itm = new GlideRecord('sc_task');


itm.addQuery('request_item',reqitm.sys_id);


itm.query();


while(itm.next())


{


  itm.opened_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';


  itm.u_requested_by = 'gh4f6854db0a1200b9e63bc0cf9619b5';


  itm.u_requested_date = gs.nowDateTime();


  itm.description = 'Manual Task Creation';


  itm.short_description = 'Manual Task Creation';


  itm.update();


}