current.assignment_group is not working in Business rules

Mr_Blue
Tera Expert

Hello Guys,

can you please suggest what to do here, in the below code so that things will work fine again .

 

My Code :

 var grProblem = new GlideRecord('problem');
grProblem.initialize();
grProblem.setValue('short_description', 'PRB generated from P1 ' + current.getDisplayValue());
grProblem.insert();
current.assignment_group='Database Atlanta';         // Not working 
current.assigned_to='bow.ruggeri@example.com';   // Not working 
current.setValue('problem_id', grProblem.getUniqueValue());
current.update();

 

Thank you in advance

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

hello Bright,

As assignment_group & assigned_to is reference field, you need to pass a sys_id of assignment_group & assigned_to.

current.assignment_group='SYS ID of Database Atlanta';         // Not working 
current.assigned_to=' SYS ID of bow.ruggeri@example.com';   // Not working 

OR

Try using below code:

current.setDisplayValue('assignment_group','Database Atlanta');
current.setDisplayValue('assigned_to','bow.ruggeri@example.com');

For more details: 

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_GlideRecord-setDisplayValue_String_O...

Few recommendations:

1. I would recommend to use grProblem.getValue('sys_id') in place of grProblem.getUniqueValue();\

2. If you are using BEFORE BR then No Need to of current.update();

3. If you are using AFTER BR then you can add one more line current.setWorkflow(false); before current.update(); OR Not to use current.update(); 

https://docs.servicenow.com/bundle/madrid-application-development/page/script/business-rules/referen...

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

6 REPLIES 6

AbhishekGardade
Giga Sage

hello Bright,

As assignment_group & assigned_to is reference field, you need to pass a sys_id of assignment_group & assigned_to.

current.assignment_group='SYS ID of Database Atlanta';         // Not working 
current.assigned_to=' SYS ID of bow.ruggeri@example.com';   // Not working 

OR

Try using below code:

current.setDisplayValue('assignment_group','Database Atlanta');
current.setDisplayValue('assigned_to','bow.ruggeri@example.com');

For more details: 

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_GlideRecord-setDisplayValue_String_O...

Few recommendations:

1. I would recommend to use grProblem.getValue('sys_id') in place of grProblem.getUniqueValue();\

2. If you are using BEFORE BR then No Need to of current.update();

3. If you are using AFTER BR then you can add one more line current.setWorkflow(false); before current.update(); OR Not to use current.update(); 

https://docs.servicenow.com/bundle/madrid-application-development/page/script/business-rules/referen...

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Hey Thank you Abhishek Gardade 🙂

The SN Nerd
Giga Sage
Giga Sage

Abhieshek has provided some great information. Supplementing his advice, I would solve this by following the steps below.

  1. When setting more than one reference field to a static value, I'd recommend using Templates.
    Create a Template on the Incident table called 'System - P1 Incident - Database Atlanta'.
    Please note that this solution assumes your Group and User Sys ID's are the same in each environment, otherwise you will have to use System Properties.
  2. Populate 'Short description' with a note indicated that it is used by your Business Rule (specify which one)
  3. Populate 'Assignment Group' to "Database Atlanta" and 'Assigned to' "Bow Ruggeri". 
  4. Ensure Template does not have 'Global' checked and is assigned to a system user such as admin
  5. This is one of the rare circumstances where you have to use current.update() on an after Business Rule. This should generally be avoided but I see no choice here.
    Ensure 'When' is set to "After"
  6. Populate your Advanced Script as follows:
    var grProblem = new GlideRecord('problem');
    grProblem.initialize();
    grProblem.setValue('short_description', 'PRB generated from P1 ' + current.getDisplayValue());
    grProblem.insert();​
    
    // current.update() must be used here, as the relationship to the problem is stored on the incident record which has already been updated.
    
    current.applyTemplate('System - P1 Incident - Database Atlanta');​
    current.setValue('problem_id', grProblem.getValue('sys_id'));
    current.setWorkflow(false); // Prevent recursive update to Incident
    current.update();

     


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hey Thank You Paul Morris 🙂