Background script (it should not create new records)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 09:03 PM
Hi! I'm having a hard time fixing this background script below. The script is working however, it creates new records in the vtb_task table. Am I missing something? Thank you in advance 🙂
var current = new GlideRecord('vtb_card');
current.query();
while (current.next()){
var vtbtask = new GlideRecord('vtb_task');
vtbtask.addQuery('sys_id', current.task);
vtbtask.query();
if (vtbtask.next()) {
vtbtask.setValue('u_choice_2', 'no');
} else {
vtbtask.setValue('u_choice_2', 'yes');
}
vtbtask.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 10:08 PM
Just remove the else section for it, it will just update the record as No for this field u_choice_2
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 09:25 PM
Hi,
Try to add
vtbtask.setWorkflow (false);
Before vtbtask.update (); line.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 09:36 PM
Hi @Sagar Pagar , added the this vtbtask.setWorkflow (false); before vtbtask.update (); line, but still creates new records.
Thanks,
Sab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 09:40 PM
Hi @ss123,
it should be w/o space in between setWorkflow and (false);
vtbtask.setWorkflow(false);
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 09:56 PM
Hi @Sagar Pagar
This is the updated script, result was, it just inserts records with u_choice_2 field = Yes
var current = new GlideRecord('vtb_card');
current.query();
while (current.next()){
var vtbtask = new GlideRecord('vtb_task');
vtbtask.addQuery('sys_id', current.task);
vtbtask.query();
if (vtbtask.next()) {
vtbtask.setValue('u_choice_2', 'no');
} else {
vtbtask.setValue('u_choice_2', 'yes');
}
vtbtask.setWorkflow(false);
vtbtask.update();
}
Thanks,
Sab