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 03:13 AM
Its working because you removed setWorkflow(false)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 04:39 AM - edited 05-31-2024 04:45 AM
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