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:51 PM
Hi @Aman Kumar S yes it should be current.task , because the "task" is a field in the vtb_card , referencing the current vtb_task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 10:56 PM
No "task" is a field of card GlideRecord variable. There is no current in background script. If you are using this in business rule, then don't use gliderecord on vtb_card. Directly use
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 11:22 PM
There's still error in the current
vtb_card is a related list of vtb_task. and the reason is that I want to validate if the vtb_task has a value in the vtb_card related list
Thanks,
Sab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 10:47 PM
In background script, there is no current. So you have to go with card.task only. You have to keep using setWorkflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 10:53 PM
Well, it should be current.task , because the "task" is a field in the vtb_card , referencing the current vtb_task. I hope I explained it well. 🙂