Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hi rahul

Use this code and also verify logs.

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.initialize();
grScTask.request_item = ritm;
grScTask.assignment_group = '9efc96a71b2909105cf40f6cdc4bcb45';//map your group here
grScTask.assignment_to = 'ebb5217a87cd4910d0d4ca27cebb3505';
grScTask.u_sub_category = 'Tasks';
//map all your fields here
grScTask.insert();

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

find_real_file.png

 

in SC Task

You want to update existing task or create a new one? what is not mapping from above code?

can you share more details along with screenshot?

 

for assigned to mapping use this.

grScTask.assigned_to = 'ebb5217a87cd4910d0d4ca27cebb3505';

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

i want to create a new task , 

from above script i am trying to populate ssignment group, assigned to and sub category

find_real_file.png

can you confirm if RITM value is mapping properly?

Are you mapping proper group details?

you should map back-end value of 'Tasks' for sub-category.

gs.info("RITM Info "+ritm);
var grScTask = new GlideRecord('sc_task');
grScTask.initialize();
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.insert();

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