g_form.getFieldNames() on Portal Only - Why?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 08:12 AM
Can someone please explain to me WHY there is no straightforward way to get a list of the field names on a regular old Form?
Apparently the g_form.getFieldNames() function is ONLY available if you are in the context of the Service Portal.
I can't for the life of me understand why that would be; although I'm sure there is a reason.
What is the reason? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 08:21 AM
Hi @G24
I think there is no OOB method as of now available for this. But you can write code as below in client script:-
var arr = [];
for (var x = 0; x < g_form.elements.length; x++) {
arr.push(g_form.elements[x].fieldName);
}
alert("array value = " + arr);
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 08:44 AM
You didn't answer my actual question, @Gunjan Kiratkar , but that was still helpful, thank you.
I ended up writing the following UI Policy script to make fields ReadOnly or NOT. Hopefully this is OK to do:
It's strange to me that there is a g_form method for enumerating the EDITABLE fields, but not ALL the fields. I just don't get it. Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 05:17 AM
Hello there is also option
g_form.getFieldNames();
It is answer from other stream - https://www.servicenow.com/community/developer-forum/is-there-some-easier-way-to-get-all-the-field-n...