- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 05:03 AM
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();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 07:02 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 06:08 AM
HI Ketan
Can u pls try this
Script:
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';
createRequest();
function createRequest() {
//Create Request
var grRequest = new GlideRecord ("sc_request");
grRequest.initialize();
grRequest.requested_for = 'gh4f6854db0a1200b9e63bc0cf9619b5';
grRequest.short_description ='heloo ketan';
grRequest.description ='heloo ketan';
var requestSysId = grRequest.insert();
//Create Request Item
current.requested_for = 'gh4f6854db0a1200b9e63bc0cf9619b5';
current.short_description = 'heloo ketan';
current.description ='heloo ketan';
current.parent = requestSysId;
current.request = requestSysId;
current.request_type = 'others';
current.assignment_group='234b4edbdb771204b9e63bc0cf9619f9';
current.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 08:54 AM
This code is just creating request. No request item nor task. As well as how this will trigger workflow? As the code which I have is already creating Request/RITM/Task but not triggering work flow. Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2017 10:01 PM
Hi Ketan
OOB functionality every catalog item can create a request and RITM automatically based on the some conditions some tasks can be created as per our requirements
so better to craete a run script activity and place the below code under that
if(current.variables.v_check1== 'true')//create some conditions for creating a task
{
var tsk = new GlideRecord('sc_task');
tsk.initialize();
tsk.request_item = current.sys_id;
tsk.assignment_group = '5f6441efc0a8010e0177fcb589156352'; //assignment of some group for task
tsk.short_description = 'test';
tsk.insert();
}
if(current.variables.v_check2== 'true')//create some conditions for creating a task
{
var tsk = new GlideRecord('sc_task');
tsk.initialize();
tsk.request_item = current.sys_id;
tsk.assignment_group = '5f6441efc0a8010e0177fcb589156352'; //assignment of some group for task
tsk.short_description = 'test';
tsk.insert();
}
my workflow look like this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2017 10:05 PM
Hello Ketan,
Please go through the below blog and adjust your code accordingly. Sample ex 3:
Request Generation Methods — ServiceNow Elite