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

You can do something like this in your UI Script:



//Your UI Script Method below


//gform: Optional unless calling from Service Portal


function UIScriptMethod(parm1, gform ) {


if (g_form == undefined) {


      g_form = gform;


}


g_form.setDisplay(parm1,false);


}



And in your Client Script:



function onLoad() {



UIScriptMethod('state',g_form);



}



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

This works in service portal as well. Thanks Paul.


The SN Nerd
Giga Sage
Giga Sage

Has anyone else found a solution or any neat workarounds?


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