Client Script why can't use g_form.getQueryParameter

KelvinY2025
Tera Contributor

function onLoad() {
var myparam = g_form.getQueryParameter('myparam');

....
}

why ? 
(g_env) [SCRIPT:EXEC] Error while running Client Script "Incident Demo01": TypeError: g_form.getQueryParameter is not a function

how to do ?

10 REPLIES 10

adityahubli
Tera Contributor

Hello @KelvinY2025 ,

In ServiceNow, g_form =ONLY form fields control. It does not read URL parameters. 

g_form.getQueryParameter() does not exist — that’s why you are getting:

TypeError: g_form.getQueryParameter is not a function

 

Correct method to access parameters,

 

function onLoad() {
var myparam = g_url.getParameter('myparam');
console.log(myparam);
}

 

If this helps you then mark it as helpful and accept as solution for future queries.

Regards,

Aditya

js_includes_clientSc0-11-2025_0527:5568 (g_env) [SCRIPT:EXEC] Error while running Client Script "Incident Demo01": ReferenceError: g_url is not defined

 

 

 

KelvinY2025_0-1764208658107.png

KelvinY2025_1-1764208701094.png

 

Used under sow, it doesn't work

Sarthak Kashyap
Mega Sage

Hi @KelvinY2025 ,

 

User below code to retrieve query parameters from the URL

 

var myparam = g_form.getParameter("sysparm_myparam");

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

KelvinY2025_0-1764208837508.png

KelvinY2025_1-1764208878339.png

 

Used under sow, it doesn't work