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:49 AM
Hi,
So what is your requirement here? what's the use case of getting all variables?
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 03:08 AM
We want catalog item approval notification to be sent will all variables which are shown on the form when user submitted the service catalog request

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 02:52 AM
why dont you use server side script here ,
Create on email script and use in your notification.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
if(current.cat_item.name =='Item Name'){
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if (vs.get(i).getDisplayValue() != '' && +vs.get(i).getLabel() != '') {//should take care of variables like split that does not have any label & also variable where no value is entered
template.space("5");
template.print("\n"+vs.get(i).getLabel()+"="+vs.get(i).getDisplayValue()+"\n");
}
}
}
})(current, template, email, email_action, event);
Note: I am assuming your notification is running on sc_req_item table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 03:09 AM
We tried this but it includes hidden variable . few variables are hidden by ui policy based on any other variable. we dont want those to be sent to approvers because they get confused.