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

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 ?

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.

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

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

We need generic for all catalog items. so we cannot specifically mention variable name

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.