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.

Issue with the background script

Pooja Khatri
Tera Contributor

I am trying to update my work notes from the background script for condition where impact is null and then impact is set to 5 but my worknotes are not getting updated 

 

Why is the Background script not working ?

Background Script : 

 

My work notes are not getting updatd with the below script

var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^impact=NULL');

var text = 'See the following kb article for more info: ';
var url = '[code]<a href="' + 'https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0867584' + '" target="_blank">' + 'Knowledge Article View - Employee Support Center' + '</a>[/code]';
gr.query();

while (gr.next()) {
if (gr.priority == '5') {
gr.impact = '5';
gr.urgency = '3';
gr.work_notes= text + url;
gr.setWorkflow(false);
gr.update();
}

}

6 REPLIES 6

Its working because you removed setWorkflow(false)

 

-Anurag

swathisarang98
Giga Sage

Hi @Pooja Khatri ,

 

Use 'gr.work_notes.setJournalEntry(text + url);' instead of gr.work_notes= text + url; and i think there is a conflict between impact and priority because when impact is 3 and urgency is 3 you will get priority as 5 (planning) but here priority is 5 and you are setting impact as 5 it might be wrong please do check that aswell.

 

 

 

var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^impact=NULL');

var text = 'See the following kb article for more info: ';
var url = '[code]<a href="' + 'https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0867584' + '" target="_blank">' + 'Knowledge Article View - Employee Support Center' + '</a>[/code]';
gr.query();

while (gr.next()) {
if (gr.priority == '5') {
gr.impact = '3';
gr.urgency = '3';
gr.work_notes.setJournalEntry(text + url);
gr.update();
}

}

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang