Background script g_form is not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 01:02 PM
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);
}
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 01:05 PM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 01:29 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 01:53 PM
Yeah this helps, thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 01:59 PM
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!