- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 10:54 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2018 06:05 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 12:22 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 12:53 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 01:14 PM
Can you post what you have thus far?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 01:15 PM
I should add: also post output values if possible. Or at least dummy representations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 01:19 PM
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.