Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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 ?

4 REPLIES 4

palanikumar
Giga Sage
Giga Sage

I think it is getParameter. Try this code

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

....
}

Thank you,
Palani

SumanthDosapati
Mega Sage
Mega Sage

@KelvinY2025 

The g_form.getQueryParameter() method is not a standard or documented method in ServiceNow's g_form API. The correct and widely used method for retrieving URL query parameters in client-side scripts is g_form.getParameter(). 

 

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

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

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