Issue with the background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 01:46 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 02:03 AM
Hi,
You wont be able to update worknotes if you are using gr.setWorkflow(false);
Remove that and then it will update work notes too, but then you open yourself to the risk of triggering other BRs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 02:04 AM - edited 05-31-2024 02:06 AM
Hi @Anurag Tripathi - tes post removing I am able to update the worknotes but it will trigger the Business rules , any other way I can handle this scenario ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 02:15 AM
trying to split update in 2
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.setWorkflow(false);
gr.impact = '5';
gr.urgency = '3';
gr.update();
gr.setWorkflow(true);
gr.work_notes= text + url;
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 03:09 AM
Hi @Pooja Khatri ,
I tried your script in my PDI and it works for me please check below script
var gr = new GlideRecord('incident');
// gr.addEncodedQuery('active=true^impact=NULL');
gr.addEncodedQuery('active=true^impact=3');
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();
if (gr.next()) {
if (gr.priority == '5') {
gs.print("Num = " + gr.number);
gr.impact = '5';
gr.urgency = '3';
gr.short_description = "Test1q23";
gr.work_notes = text + url;
gr.update();
}
}
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak