- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 10:37 AM
Hello Community,
Requirement: If the particular field of the requested item record is true then auto create catalog task for the requested item.
I have created a business rule to achieve this. But the task is getting created on every update of the requested item record.
I want the catalog task to be created once and if the requested item is updated then the existing task needs to update instead of creating new catalog task each time.
Any inputs how to achieve this?
Thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 03:29 AM
@ShraddhaMore Please try this updated script, I forgot to add method brackets () in current.operation().
(function executeRule(current, previous /*null when async*/ ) {
if (current.cat_item.name == "Request email alias" && current.u_create_task == true && current.operation() == 'insert') {
// Create a new catalog task
var task = new GlideRecord('sc_task');
task.initialize();
task.request_item = current.sys_id;
task.short_description = 'Auto-generated task';
task.state = current.state;
task.setDisplayValue('assignment_group', 'App Engine Admins');
task.u_stage = current.stage;
task.u_boolean_1 = current.u_create_task;
task.insert();
} else {
//Update exusting task
var existingTask = new GlideRecord('sc_task');
existingTask.addQuery('request_item', current.sys_id);
existingTask.query();
if (existingTask.next()) {
existingTask.short_description = 'Auto-generated task';
existingTask.state = current.state;
existingTask.setDisplayValue('assignment_group', 'App Engine Admins');
existingTask.u_stage = current.stage;
existingTask.u_boolean_1 = current.u_create_task;
existingTask.update();
}
}
})(current, previous);
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 11:00 AM
@ShraddhaMore Please update your business rule script as follows and it should create only one task during insert and update it during the time of update.
(function executeRule(current, previous /*null when async*/ ) {
if (current.cat_item.name == "Request email alias" && current.u_create_task == true && current.operation == 'insert') {
// Create a new catalog task
var task = new GlideRecord('sc_task');
task.initialize();
task.request_item = current.sys_id;
task.short_description = 'Auto-generated task';
task.state = current.state;
task.setDisplayValue('assignment_group', 'App Engine Admins');
task.u_stage = current.stage;
task.u_boolean_1 = current.u_create_task;
task.insert();
} else {
//Update exusting task
var existingTask = new GlideRecord('sc_task');
existingTask.addQuery('request_item', current.sys_id);
existingTask.query();
if (existingTask.next()) {
existingTask.short_description = 'Auto-generated task';
existingTask.state = current.state;
existingTask.setDisplayValue('assignment_group', 'App Engine Admins');
existingTask.u_stage = current.stage;
existingTask.u_boolean_1 = current.u_create_task;
existingTask.update();
}
}
})(current, previous);
Please mark the answer helpful and correct if it addresses your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 03:09 AM
@Sandeep Rajput , it's updating the existing catalog task, but not creating new task if there isn't any already existing task for request item.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 03:29 AM
@ShraddhaMore Please try this updated script, I forgot to add method brackets () in current.operation().
(function executeRule(current, previous /*null when async*/ ) {
if (current.cat_item.name == "Request email alias" && current.u_create_task == true && current.operation() == 'insert') {
// Create a new catalog task
var task = new GlideRecord('sc_task');
task.initialize();
task.request_item = current.sys_id;
task.short_description = 'Auto-generated task';
task.state = current.state;
task.setDisplayValue('assignment_group', 'App Engine Admins');
task.u_stage = current.stage;
task.u_boolean_1 = current.u_create_task;
task.insert();
} else {
//Update exusting task
var existingTask = new GlideRecord('sc_task');
existingTask.addQuery('request_item', current.sys_id);
existingTask.query();
if (existingTask.next()) {
existingTask.short_description = 'Auto-generated task';
existingTask.state = current.state;
existingTask.setDisplayValue('assignment_group', 'App Engine Admins');
existingTask.u_stage = current.stage;
existingTask.u_boolean_1 = current.u_create_task;
existingTask.update();
}
}
})(current, previous);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 03:44 AM
@Sandeep Rajput still not working, only updating the existing catalog task, but not creating new task if there isn't any already existing task for request item.