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.

Background script (it should not create new records)

ss123
Tera Contributor

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();
}

19 REPLIES 19

Davedd90
Tera Contributor

Please use "card" or "vtbcard" instead of current variable and see if it works.

ss123
Tera Contributor

Hi @Davedd90 , I got an error, see below

SabrinaSalazar_0-1669703603544.png

 

Update line 5 as 

card.task

Best Regards
Aman Kumar

Hi @Aman Kumar S , it did not update the records. It only created new records. 

Also the current.task pertains to the current task 🙂

@ss123 ,

If you check your script, you are storing gliderecord reference in "Card" variable and now you are using current in 5th line, that's what throwing the error.

 

Best Regards
Aman Kumar