Background script g_form is not defined

anfield
Tera Guru

Running a background script against our location table, parent field (parent is a reference field)


What I am trying to do is search for any locations that have a parent field, with 32chars exactly delete them (I need to add the delete portion also). When I run the below background script. I get the following error - 

Can anyone help? Thanks

Evaluator: org.mozilla.javascript.EcmaError: "g_form" is not defined.
   Caused by error in script at line 6

This line -

==>   6:                 var parent = g_form.getValue('parent');

var grloc = new GlideRecord('cmn_location');
grloc.query();

while(grloc.next()){

var parent = g_form.getValue('parent');
if (parent.toString().length == 32) {

gs.log('Location name has a parent with +32chars:' + grloc.name);
}
}

9 REPLIES 9

Allen Andreas
Administrator
Administrator

Hi,

You can't use g_form in background script as g_form is client side code.

You'd most likely need to use:

var parent = grloc.parent;

Essentially think of it as your variable for the query...is now the "current" or "g_form" now...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

var parent = grloc.parent.name;
gs.print("This is the parent: " + grloc.parent.name);

Hi,

Try with that and see what you get.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Yeah this helps, thanks

Excellent.

Please mark my reply above as Correct as well.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!