- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 04:06 AM
Script I am using is creating two tasks and the date is not filling out the data from the sctask level please help!
Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:18 AM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 04:21 AM - edited 07-26-2023 04:22 AM
Hello @Joshua Comeau ,
It looks like there's a minor issue with your script. You're trying to set the "actual_work_start" and "actual_work_end" fields on an GlideRecord named "sc_task," which is not defined in your script. Instead, you should use the "rec" GlideRecord that represents the newly created sc_task record. Let's fix the script by updating these lines:
rec.actual_start = '2023-07-25 15:08:09';
rec.actual_end = '2023-07-26 15:08:11';
Also avoid hardcoded value here.
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 04:26 AM
When I add those lines it does not update the variable. Also two tasks are being created I believe it is because the workflow has a task its following the flow creating the task in the workflow but creating that task cause of the script how to get it to bypass the flow and also update the actual start and end date

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 04:55 AM - edited 07-26-2023 04:55 AM
if once task is creating by wf you can update that task with new values instead inserting new record
var rec= new GlideRecord('sc_task');
rec.addQuery('request_item', ritm.sys_id); // RITM sys_is
rec.query();
if(rec.next()){
rec.assignment_group = 'b101adf8dbe65b407f0264904b961972';
rec.short_description = 'Maintenance Plan - Facility Task';
rec.description = 'Replace every light on every floor';
rec.actual_work_start = '2023-07-25 15:08:09';
rec.actual_work_end = '2023-07-26 15:08:11';
rec.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 05:11 AM
@Chetan Mahajan so I can remove the entire code I had and just put this?