creating Request and Tasks from Scheduled Job

Rahul Raja Sami
Tera Guru

I used this script to generate request and its respective task from Scheduled Job

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//give sys_id of catalog item
var item = cart.addItem('016a8e91872d0110d0d4ca27cebb35b2', 1);
cart.setVariable(item,"short_description", ' Monthly Report Update ');
cart.setVariable(item,"description", " Monthly Report Update" );
var rc = cart.placeOrder();

 

and I wanted to auto populate Assignment group,Assigned to & Sub category as well.

How to do it Please help

19 REPLIES 19

by using this i can create a new ticket (req,ritm & SCtask)

 

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//give sys_id of catalog item
var item = cart.addItem('016a8e91872d0110d0d4ca27cebb35b2', 1);
cart.setVariable(item,"short_description", ' Monthly Report Update ');
cart.setVariable(item,"description", " Monthly Report Update" );
var rc = cart.placeOrder();

 

and able to populate short description and Description 

but couldn't populate Assignment group, Assigned to and sub category

Tasks backend value is the same 

 

find_real_file.png

oh looks like you want to update existing CTASK.

try this code.

var req=rc.number;
var grScReqItem = new GlideRecord('sc_req_item');
grScReqItem.addEncodedQuery("request.number=" + req);
grScReqItem.query();
var ritm;
if (grScReqItem.next()) {
ritm = grScReqItem.sys_id;

}
gs.info("RITM Info "+ritm);
var grScTask = new GlideRecord('sc_task');

grScTask.addQuery('request_item', ritm);
grScTask.query();
while (grScTask.next()) {
//grScTask.request_item = ritm;
grScTask.assignment_group = '9efc96a71b2909105cf40f6cdc4bcb45';//map your group here
grScTask.assigned_to = 'ebb5217a87cd4910d0d4ca27cebb3505';
grScTask.u_sub_category = 'Tasks'; //use backend value
grScTask.update();
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

no i want to create the sc task so please suggest me what to add to my present code

Can you share your complete requirement please with screenshots if possible.

you mentioned you're able to populate short description and description, can you show how that is mapped?


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP