g_form.geFieldNames() not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 02:40 AM
I am using catalog client script on submit as below
var allFields = g_form.getFieldNames();
for(var fieldName in allFields){
alert( allFields[fieldName]);
}
it is not working and not allowing to submit the form.
is g_form.getFieldNames() is deprecated? If yes any other way to get all variables shown on the form to get populated in client script ?
We like to send notification with variables only variables shown on the form even user didnt provide info in those variables. hidden variables through UI script shouldnt be sent.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 02:59 AM
Hi Chitra,
You can use something like this:
var allFields = g_form.getFieldNames();
for(i = 0; i < allFields.length; i++) {
alert( ----);
}
Try this. It may works.
Kindly mark the answer as Correct and Helpful if this answers your question.
Thank You.
Regards,
Geetanjali Khyale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 03:12 AM
I have already tried this i am getting below error
Error MessageonSubmit script error: TypeError: g_form.getFieldNames is not a function:
function () { [native code] }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2022 01:15 AM
This is not working for me. I am trying to write an OnChange client script. Please guide me through.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 03:13 AM
Hi,
Write an onLoad Catalog Client script for your catalog item and write below code:-
var a = document.getElementsByTagName('label');
for(i=0;i<a.length;i++)
{
alert(a[i].innerHTML);
}
Or
You can write the script as below:-
var grRequestedItem = new GlideRecord('sc_req_item');
grRequestedItem.setLimit(10);
grRequestedItem.query();
while (grRequestedItem.next()) {
gs.addInfoMessage('Variables for ' + grRequestedItem.getDisplayValue());
for (var prop in grRequestedItem.variables) {
if (grRequestedItem.variables.hasOwnProperty(prop) ){
var variable = grRequestedItem.variables[prop];
gs.addInfoMessage(prop + ':' + variable);
}
}
}
Please follow the below link for more:-
https://community.servicenow.com/community?id=community_blog&sys_id=bd6eeeaddbd0dbc01dcaf3231f96195a
If i was able to solve your query, please mark my answer correct and helpful.
Thanks & Regards
Prasant kumar sahu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 03:24 AM
This one also show hidden variable through ui policy. we want only which was shown on the form