g_form.geFieldNames() not working

chitra11
Tera Contributor

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. 

19 REPLIES 19

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So what is your requirement here? what's the use case of getting all variables?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

Harsh Vardhan
Giga Patron

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. 

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.