- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 10:37 PM
Hi all,
I have a scenario:
in incident form, if the priority changes to 1, a new incident should be created with the same details of the current incident but the assigned to should be the 'manager of the assignment group'. the incident is getting created but assigned to is not getting updated.
I've written an after BR with conditions.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 11:40 PM
Hello @abjaffrey ,
You can use this to achieve your requirement.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var newInc = new GlideRecord('incident');
var assignment = current.assignment_group.manager;
newInc.initialize();
newInc.description = 'This is created as the priority was changed to 1'+'\n'+current.description;
newInc.assignment_group = current.assignment_group;
newInc.impact = 1;
newInc.urgency = 1;
newInc.assign_to = assignment; //This will set the manager in assigned_to field.
newInc.caller_id = current.caller_id;
newInc.category = current.category;
newInc.short_description = current.short_description;
newInc.assigned_to = assignedTo;
newInc.insert();})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 12:44 AM
Hi @abjaffrey ,
There is a minor mistake in your code, in the following section. I have commented down the correct condition and highlighted it with bold font. Change "grpDetails.name" to "grpDetails.sys_id" and your code should work.
===============================================

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 01:33 AM
@abjaffrey Here is the updated script, please see if it works.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var newInc = new GlideRecord('incident');
newInc.initialize();
newInc.description = 'This is created as the priority was changed to 1'+'\n'+current.description;
newInc.assignment_group = current.assignment_group;
newInc.impact = 1;
newInc.urgency = 1;
newInc.caller_id = current.caller_id;
newInc.category = current.category;
newInc.short_description = current.short_description;
// newInc.insert();
var grpDetails = new GlideRecord('sys_user_group');
var assignedTo = '';
grpDetails.addEncodedQuery('nameINNetwork,Hardware,Network CAB Managers');
grpDetails.query();
while(grpDetails.next())
{
if(grpDetails.getValue('sys_id') == current.getValue('assignment_group'))
{
assignedTo = grpDetails.manager+'';
}
}
newInc.assigned_to = assignedTo;
newInc.insert();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2024 01:35 AM
Your script looks mostly correct, but there are a few improvements and corrections needed to ensure that the assigned_to
field is properly updated with the manager of the assignment group. Here are the key changes:
- Ensure you are comparing the correct fields when matching the
assignment_group
. - Fetch the
manager
field value correctly from thesys_user_group
record. - Insert the new incident record only after setting all required fields.
Here is the revised script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
// Create new incident
var newInc = new GlideRecord('incident');
newInc.initialize();
newInc.description = 'This is created as the priority was changed to 1' + '\n' + current.description;
newInc.assignment_group = current.assignment_group;
newInc.impact = 1;
newInc.urgency = 1;
newInc.caller_id = current.caller_id;
newInc.category = current.category;
newInc.short_description = current.short_description;
// Fetch manager of the assignment group
var grpDetails = new GlideRecord('sys_user_group');
if (grpDetails.get(current.assignment_group.sys_id)) {
var assignedTo = grpDetails.manager;
newInc.assigned_to = assignedTo;
}
newInc.insert();
})(current, previous);