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

Geetanjali Khy2
Mega Guru

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

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] }

This is not working for me. I am trying to write an OnChange client script. Please guide me through.

Prasant Kumar 1
Kilo Sage

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

This one also show hidden variable through ui policy. we want only which was shown on the form