Script for create a new task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 06:45 AM
Hi everybody ! I need to create a new task from another task. So I've used a BR, but I think something is wrong with my script, somebody could help me and tell me how to correct it? Thanks.
The script in the BR (I set condition when to run with update and insert and when the state changes to 'waiting for delivery'):
(function executeRule(current, previous /*null when async*/) {
var task = new eyRmaNcUtils();
task.assignment_group = '445334299780e1981fadb6e3f153aff2'; //change assignment group in the new one
task.current.state = 160; //set the state of the new task
current.update();
action.setRedirectURL(current);
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 06:53 AM
Hi @Alessia Russo ,
You need to use an insert script.
var newTask = new GlideRecorord("tableName");
newTask.initialize();
newTask.assignment_group = '445334299780e1981fadb6e3f153aff2'; //change assignment group in the new one
newTask.current.state = 160; //set the state of the new task
newTask.insert();
action.setRedirectURL(current);
Please mark helpful, if you find this suggestion helpful.
Please mark correct, if you find my answer solved your query.
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 06:53 AM - edited 01-09-2023 06:54 AM
Never use current.update() in a business rule. You can start by removing that line of code.
Next, we'll need to see the code for the script include "eyRmaNcUtils()" can you post that code please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2023 03:03 AM
Hi @Mike_R ! I've created a new script include (so instead of a Br I can do it all in a UI Action) and how it's like this but it didn't create me a task anyway:
var CNewTask = Class.create();
CNewTask.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
createNewTask: function(current) {
var task_sys_id = current.sys_id;
var newTask = new GlideRecord('sn_customerservice_task');
newTask.parent = task_sys_id;
newTask.assignment_group = "445334299780e1981fadb6e3f153aff2";
newTask.setValue('state', 160);
newTask.insert();
return current;
},
I've to create always the new task from another task, maybe I've put wrong the parent? Because I've to start from the task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2023 09:51 AM
Alessia,
You need to know what the eyRmaNcUtils script include doing. You shouldn't put sys_ids inside of scripts...You should use a property for one instead but for Assignment Groups you should use an Assignment Rule.
Look at @Basheer's response for how to script a new record except the line "newTask.curreent.state = 160" that should just be "newTask.state = 160".