Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Set Value from Background script

shid077
Tera Contributor

How to set priority value to 1 from background script on the incident shown below.

 

i need the query to set the priority value to 1 and assignment value also to "Database".

 

shid077_0-1707997346110.png

 

7 REPLIES 7

Community Alums
Not applicable

Hi @shid077 ,

Please refer to the script mentioned in the link , just make sure you use "incident" for querying the table and fields as per your requirement :

https://www.servicenow.com/community/itsm-forum/need-background-script-for-changing-a-field-value/m-...

 

Adrian Ubeda
Mega Sage

Hello @shid077 , 

This field it's based on impact and urgency, if you want to modify this field from BG script you will need to use setWorkflow(false); function for not triggering BR properly. Be sure about the query your are applying having all executions under control, your code should look something similar as follows:

var grInc = new GlideRecord('incident');
grInc .addQuery('sys_id', '57af7aec73d423002728660c4cf6a71c');
grInc .query();
grInc .setWorkflow(false);

if(grInc .next()) {
    grInc .setValue('priority', 1);
    grInc .update();
}

 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Aniket Chavan
Tera Sage
Tera Sage

Hello @shid077 ,

 

Please refer the script below and see how it works for you.

 

// Specify the incident sys_id or any other condition to identify the target incident
var incidentSysId = '57af7aec73d423002728660c4cf6a71c';

// Set the new values
var newPriority = 1;

// Get the incident record
var incidentGr = new GlideRecord('incident');
incidentGr.addQuery('sys_id', incidentSysId);
incidentGr.query();
incidentGr.setWorkflow(false); // Disable triggering of Business Rules

// Check if the incident record is found
if (incidentGr.next()) {
    // Update the priority
    incidentGr.setValue('priority', newPriority);

    // Update the record
    incidentGr.update();

    gs.info('Incident ' + incidentSysId + ' updated successfully.');
} else {
    gs.error('Incident ' + incidentSysId + ' not found.');
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

VaishnaviShinde
Kilo Sage

Hello @shid077 ,

Please refer below script , priority  will automatically set when we set urgency and impact to 1.

 

var gr = new GlideRecord('incident');
gr.addQuery('sys_id','965c9e5347c12200e0ef563dbb9a7156'); //add your record sys_id
gr.query();
if(gr.next()){
    gr.impact= 1;
    gr.urgency= 1 ;
    gr.assignment_group = '74ad1ff3c611227d01d25feac2af603f'; //add your group sys_id here
    gr.update();
}

 

 

If my response helped you, please mark it as accepted solution and helpful.

Regards,

Vaishnavi Shinde