Need help

abjaffrey
Giga Guru

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.

 

(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.name == current.assignment_group)
        {
            assignedTo = grpDetails.manager;
        }
    }
   
    newInc.assigned_to = assignedTo;
    newInc.insert();


})(current, previous);
2 ACCEPTED SOLUTIONS

Abhishek_Thakur
Mega Sage

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);

View solution in original post

HrishabhKumar
Kilo Sage

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.

===============================================

  while(grpDetails.next())
    {
        if(grpDetails.name == current.assignment_group)
       //if(grpDetails.sys_id == current.assignment_group)
        {
            assignedTo = grpDetails.manager;
        }
    }
============================================
NOTE:
Additionally you don't even have to Glide the Groups table to get the manager you can directly access it as follows:
current.assignment_group.manager;
 
Hope this solves your issue,
 
Thanks & Regards
HRISHABH KUMAR

View solution in original post

6 REPLIES 6

Abhishek_Thakur
Mega Sage

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);

@Abhishek_Thakur 

 

Thanks for your help, it worked

HrishabhKumar
Kilo Sage

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.

===============================================

  while(grpDetails.next())
    {
        if(grpDetails.name == current.assignment_group)
       //if(grpDetails.sys_id == current.assignment_group)
        {
            assignedTo = grpDetails.manager;
        }
    }
============================================
NOTE:
Additionally you don't even have to Glide the Groups table to get the manager you can directly access it as follows:
current.assignment_group.manager;
 
Hope this solves your issue,
 
Thanks & Regards
HRISHABH KUMAR

@HrishabhKumar 

 

Thanks for your help & suggestion.