Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to extract the id from URL

ursnani
Giga Guru

Hi All,

I am using a Business Rule to Extract the URL parameters and I was able to get the output, but now problem is i have to extract the id from the URL.

I have used "gs.action.getGlideURI().getMap().get('sysparm_query')" to get the parameters of sysparm_query.

in that Query i have like u_field1=12345678909876543212345678^u_field2=nul.

now my requieremnt is to extract the id of Field1.

Can someone please help with this.

Thanks.

1 ACCEPTED SOLUTION

ChrisBurks
Giga Sage

Another way of doing this and making it a reusable script with access to any parameters retrieved is as the following:

function parseSysparmQuery(parameters){
	var params = parameters + "";
	return params.split("^").reduce(function(acc,curr){
		var arr = curr.split("=");
		acc[arr[0]] = arr[1];
		return acc;
	},{})
}

Use it as follows:

var sysparmQuery = gs.action.getGlideURI().getMap().get('sysparm_query');
var getParam = parseSysparmQuery(sysparmQuery);

gs.info("u_field1: " + getParam.u_field1);
gs.info("u_field2: " + getParam.u_field2);

 

It could be included in a Script Include allowing it to be used in many business rules.

View solution in original post

11 REPLIES 11

Hi Chris,

 

Thanks for sharing the code but I am getting the wrong value in the log I need the Field1 and Value but I am getting Field2 and value,

 

Where am i going wrong and where I need to correct the code ? Please guide

 

Thanks.

 

HI Chris,

 

When I checked the logs the ob value pair is pritning two time and it is taking the last obj value pair.

like I am getting u_field1,123456789012345678 and u_field2, null and  it is printing only the last statement which is u_field2 , null but not u_field1 1234567890123456

 

Can you please help a little bit i think I am getting closer

Can you post what you have thus far?

I should add: also post output values if possible. Or at least dummy representations

Fow what I did is like as the fields are static I have given a condition 

if(obj.field == 'u_field1'){

current.u_field1= obj.value;

}

this has done the trick for me but i know this is not how it should be done.

 

But anyways any improvements for the Code please let me know.