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 03:24 AM
if variable is hidden then i am assuming that is empty? then above script wont consider it , because it has condition to skip empty variables .
may i know those hidden variables type ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 03:58 AM
No, Hidden i mean ui policies. for example if i choose variable A value as x then only variable B will be visible. So in the notification also the ui policy should work. it shouldnt give both A and B variable. If only A value is x then only B should be sent in email.
So we thought if we collect all variables names shown on the form during submission we can get their values later in the email script and send email.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 04:42 AM
Hi,
you will have to script that using email script using if else condition
I assume your email is on sc_req_item table then you can use current.variables.<variableA> in script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 04:52 AM
We need generic for all catalog items. so we cannot specifically mention variable name

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 04:50 AM
the script which i shared, is it also considering variable B ?
my assumption here, if you have ui policy applied on variable A drop down value to hide the variable B,
so it means , your variable B is hidden which has no value there then it will not appear in the result . can you share some output here. also add some screenshot.