How to get value/string from URL after & symbol .

Neelavathi M
Tera Contributor

Hi All,

 

I have a requirement to populate the value from URL, actual value is(&sysparm_phase=6%20test%20&%20plan) '6 test & plan' i am able to get till '6 test' but '& paln ' is not populating it is trimming  off, so what needs to changed in client scritpt to get full value.

Quick help is appreciated.

 

11 REPLIES 11

Najmuddin Mohd
Giga Sage

Hi @Neelavathi M ,

There's a better approach to get values.
At times you get different spaces in URL. Instead of passing of value, just pass the sys_id of the record that has the value.
And, write an On Load script and using GlideAjax get the values and fill the form.

We have seen some issues where URL were working in the different way in the Native UI and Workspaces.


If the above information helps you, kindly mark it as Helpful and Accept as a solution.
Regards,
Najmuddin.

Ravi Gaurav
Giga Sage

Hi @Neelavathi M 

 

Please find below the working solution:-

function onLoad() {
var currentUrl = top.location.href;
var queryParams = new URLSearchParams(currentUrl.split('?')[1]);
var phaseValue = queryParams.get('sysparm_phase');

if (phaseValue) {
phaseValue = decodeURIComponent(phaseValue);
alert("sysparm_phase value: " + phaseValue);
// g_form.setValue('your_field_name', phaseValue);
}
}

When passing sysparm_phase=6 test & plan, encode & as %26 in the URL (6%20test%20%26%20plan).
The script uses URLSearchParams to parse the URL and fetch the sysparm_phase value.
After extracting the parameter, decodeURIComponent() decodes any URL-encoded characters (such as %26 becoming &).

 

Ankur Bawiskar
Tera Patron

@Neelavathi M 

The issue is coming as it contains & in the url parameter value

from where are you passing the URL parameter?

share the script you are using to get the value?

Is it normal form or catalog form?

If my response helped please mark it correct and close the thread so that it benefits future readers.

in sysparm_phase value is  getting from custom choice table returning from the script include to client script.

@Neelavathi M 

you didn't answer my next question

Where are you writing this script? catalog form (native or portal) or normal form?