Error Script creating two tasks

Joshua Comeau
Kilo Sage

Script I am using is creating two tasks and the date is not filling out the data from the sctask level please help!

Script:

try{
 
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('136cdab01b50311070fb4002dd4bcb24', 1);
 
//fill in the variables on the request item form
cart.setVariable(item, "asset", "136cdab01b50311070fb4002dd4bcb24"); // asset here is variable name and since it's reference we have used sysId
var rc = cart.placeOrder();
gs.info(rc.number);
 
var ritm = new GlideRecord('sc_req_item');
if(ritm.get('request', rc.sys_id)){
var rec = new GlideRecord('sc_task');
rec.initialize();
rec.request = rc.sys_id;
rec.request_item = ritm.getUniqueValue();
rec.assignment_group = 'b101adf8dbe65b407f0264904b961972'; 
rec.short_description = 'Maintenance Plan - Facility Task';
rec.description = 'Replace every light on every floor';
sc_task.actual_work_start = '2023-07-25 15:08:09';
sc_task.actual_work_end = '2023-07-26 15:08:11';
rec.insert();
}
 
}
catch(ex){
gs.info(ex);
}
1 ACCEPTED SOLUTION

Joshua Comeau
Kilo Sage

Fixed the issue with the following code:

 

try{

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('136cdab01b50311070fb4002dd4bcb24', 1);

//fill in the variables on the request item form
cart.setVariable(item, 'what_can_we_help_you_with', "Fix lights on floor 1");
cart.setVariable(item, 'can_you_give_us_some_more_details', "this is more information");
cart.setVariable(item, 'are_you_a_member_of_the_facilities_team', "Yes");
cart.setVariable(item, 'actual_work_start', "2023-07-25 15:08:09");
cart.setVariable(item, 'actual_work_end', "2023-07-26 15:08:11");
var rc = cart.placeOrder();
gs.info(rc.number);
}
catch(ex){
gs.info(ex);
}

View solution in original post

6 REPLIES 6

Joshua Comeau
Kilo Sage

@Chetan Mahajan 

 

I found by using this code

try{

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('136cdab01b50311070fb4002dd4bcb24', 1);

//fill in the variables on the request item form
cart.setVariable(item, "short_description", "136cdab01b50311070fb4002dd4bcb24"); // asset here is variable name and since it's reference we have used sysId
var rc = cart.placeOrder();
gs.info(rc.number);
}
catch(ex){
gs.info(ex);
}

it will follow the workflow but and this is all I need but having trouble with filling out the data how to fill out the short description:

 

This line of code does not work
cart.setVariable(item, "short_description", "136cdab01b50311070fb4002dd4bcb24"); // asset here is variable name and since it's reference we have used sysId 

Joshua Comeau
Kilo Sage

Fixed the issue with the following code:

 

try{

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('136cdab01b50311070fb4002dd4bcb24', 1);

//fill in the variables on the request item form
cart.setVariable(item, 'what_can_we_help_you_with', "Fix lights on floor 1");
cart.setVariable(item, 'can_you_give_us_some_more_details', "this is more information");
cart.setVariable(item, 'are_you_a_member_of_the_facilities_team', "Yes");
cart.setVariable(item, 'actual_work_start', "2023-07-25 15:08:09");
cart.setVariable(item, 'actual_work_end', "2023-07-26 15:08:11");
var rc = cart.placeOrder();
gs.info(rc.number);
}
catch(ex){
gs.info(ex);
}