creating Request and Tasks from Scheduled Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 04:19 AM
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
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 05:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 05:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 05:46 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 05:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 05:52 AM
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