Referencing g_form in UI Script used in Service Portal

The SN Nerd
Giga Sage
Giga Sage

Hi Community,

We had a UI Script we were using to simplify Ajax calls throughout our system.

The UI Script does not work in Service Portal because 'g_form' is not defined.

We can work around this by passing in g_form as a parameter, but this seems unnecessary.

Is there a cleaner way to reference g_form from a UI Script used in Service Portal?

Thanks,

Paul

P.S. window.g_form does not work.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
12 REPLIES 12

Not without passing in g_form as a parameter.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

HI Paul,


How can I pass the g_form as a parameter into the ui script from my catalog client script?


Lets say I have ui script that control the hide and show of variables this kind of script:



g_form.setVisible("choose",false);



and I want the ui script to know the g_form.


Thanks,


Lior grinberg


You have to pass it in.

Catalog Client Script

myUIScript(g_form);

UI Script

function myUIScript(g_form) {
   g_form.addInfoMessage('hello');
}

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

dwada1
Kilo Expert

Hi Paul,



Not sure if this is Service Portal compatible, but you might be able to instantiate a new GlideForm object like so:


var gform = new GlideForm();


gform.addInfoMessage('This info message should appear at the top of the screen');


jamesmcwhinney
Giga Guru

Did you ever find a solution?


We are trying to update our catalog items to work in service portal, and we were using g_form.setDisplay( to hide variables conditionally in an onload catalog client script