Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to Get paremeter value from public survey url

JackieZhang
Kilo Sage

I have a req for adding the read only question User Name to a public survey. the value of User Name need to get from URL. how to implement it? 

8 REPLIES 8

soumyadeep10
Tera Guru

Hi @JackieZhang ,

You can use the below logic to get the user name and then you can add your own code if you want to set it to a particular field or anything else.

 var gUrl = top.location.href; //getting the URL
//fetch the parameter from url, add the replace the param_name with your parameter name.
    var uName = new URLSearchParams(gUrl).get("param_name"); 

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Sorry, where do I need to add it to? 

@JackieZhang This is a scipt to fetch the value. This can directly be used in a client script.

I saw the url that you gave as a reply. In the reply you are sending the user name as 'name' (name=jackie). 

In the script I gave, replace "param_name" with "name".
After doing so, add one line for setValue for setting the field you want to the 'name' parameter's value. Below is an example 

 
g_form.setValue('your_field_backend_name', uName);

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Ankur Bawiskar
Tera Patron

@JackieZhang 

where is the user taking survey? portal or native?

share screenshots

what's your actual business requirement?

check this

Setting value of survey question via client script 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader