How to query the table fields exists or not from the array in background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2022 10:45 AM
var gr = new GlideRecord("interaction");
var myStringArray = ["sys_created_by", "assignment_group"];
var arrayLength = myStringArray.length;
gr.query();
while (gr.next()) {
for (var i = 0; i < arrayLength; i++) {
var data = myStringArray[i];
gs.print(data + ' --> ' + gr.data);
}
}
I want to know if field values exist in a table or not.
As I have many filed values I was taught to use arrays and looping through all values.
If a field does not exist then I get not defined but it is not working can anyone help me find if field exist in the table using the background script.
I have a lot of fields to find and some have multiple references like (assignment_group.name....
) like that
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2022 10:56 AM
Hi Rahul,
Please use gr.isValidField()
i.e.
var gr = new GlideRecord("interaction");
var myStringArray = ["sys_created_by", "assignment_group"];
var arrayLength = myStringArray.length;
gr.query();
while (gr.next()) {
for (var i = 0; i < arrayLength; i++) {
var data = myStringArray[i];
gs.print(data + ' --> ' + gr.data);
if (gs.isValidField(data)) {
gs.print (' the field exists ')
}
}
}
Best Regards,
Marcin
If my answer helped you in any way, please mark this answer as helpful and correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2022 11:33 AM
It does not work for dot notations like opened_for.user_name it returns false even if the field exists.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 07:43 AM
There is a typo in the code. It should read
gr.isValidField(data)
If this answer was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel