- 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 01:56 PM
Just that little snippet of code didn't help much of where it is in the script. However, I forgot to put a return in the map method and reassing q in my previous post.
But if you're only concerned with 'u_field1' then you can modify the filter to:
var q = gs.action.getGlideURI().getMap().get('sysparm_query') + "";
q = q.split("^")
q = q.filter(function(item){
return item.indexOf('u_field1') > -1;;
}).map(function(item){
var arr = item.split("=");
var obj = {}
obj[arr[0]] = value: arr[1]
gs.log(obj.u_field1, "ACTION")
return obj;
})[0]
gs.log(q.u_field1);
Here is a breakdown:
- 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.