Testing g_form in Chrome console

Giri6
Tera Expert

Is it possible to invoked methods on g_form in the console of chrome? I tried and it did not find the object. Wondering if there is any wrapper or  in anyway. Appreciate it.

10 REPLIES 10

Instead of doing concole.log try doing alert(g_form code).  It will show in a popup. Also I noticed you had get_reference when it should be g_form.getReference('filed  name', function callback);

https://docs.servicenow.com/bundle/paris-application-development/page/app-store/dev_portal/API_refer...

Giri6
Tera Expert

Thanks Brain. I tried alert and it did not work. I am sure it worked one time in console I can type g_form. I think it worked in Chrome console otherwise in Firefox.

But I am able to use this by invoking SNOW Javacript executor using Ctrl+shift+alt+j, though it is pain to type.

find_real_file.png

JonMS
Tera Expert

I figured this out. You must right-click and inspect the page first in Chrome. Then you have access to g_form via the console.

Community Alums
Not applicable

Are you sure that's all you did? I am trying to speed up my Catalog Item client side testing by setting up some Variable values on a long form and still get this "g_form is not defined" error.

 

EDIT: seems like this only works for forms, not catalog items, as I tested the below and for anything that is not directly mapped to a target record field, a "g_form is not a function" error is returned.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0695239

Ended up using Tim Woodruff's solution instead: https://www.servicenow.com/community/developer-articles/set-catalog-variables-from-url-params-free-t... 

gregorZeiler
Tera Contributor

Hello Community,

 

to used the g_form command in the browser console, it is (sometimes) necessary to switch to the gsft_main frame.

Therefore, take a look at this Knowledge Article from ServiceNow:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0695239

 

It is then possible to create e.g. an alert - alert(g_form.getValue('<variableName>')); - or

to create a console log entry - console.log(g_form.getValue('<variableName>'));

 

Do not forget the quotation marks ' ' šŸ˜‰.