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

ark6
Mega Guru

$scope is not defined in UI Scripts



ReferenceError: $scope is not defined



I've also noticed that the Script Editor tells me 'g_form' used out of scope



out of scope.png



I want to use this in scope.



I'm looking for it to be cross-compatible, i.e.



if (g_form === undefined)


  var g_form = /*Code here*/


g_form.addInfoMessage('addInfoMessage: ' + msg);





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

Oh Sorry..my Bad. I got it wrong.



I thought you were trying the code in the client controller.



Let me take a look into it and come back


hartr
Giga Contributor

Did you get this working ?