Referencing g_form in UI Script used in Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2017 07:12 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 04:31 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2018 11:59 PM
This works in service portal as well. Thanks Paul.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2019 05:39 AM
Has anyone else found a solution or any neat workarounds?
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022