- 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 10:56 AM
Hi,
Will your fields remain the same i.e. starting string of sysparm_query will always be u_field1?
if yes then you can do string manipulation and retrieve that value
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 10:58 AM
yes they reamin same all the time as u_field1
Can you please explain how to do the manipulation ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 11:54 AM
I tried like this also
var str = gs.action.getGlideURI().getMap().get('sysparm_query').toString();
output is same "u_field1=12345678909876543212345678^u_field2=nul"
but after that how to split the values i tried inthe following way
str.split("=");
but didnt work it is coming as "Ljava.lang.String;@be669e"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2018 12:11 PM
Try assigning gs.action.getGlideURI().getMap().get('sysparm_query') and concatenating with empty quotes in a var.
Then on a new line convert to an array with split("^") as there may be more than one criteria.
Here is an example of breaking each criteria and it' s value into a separate object and placing in an array removing 'EQ' if at the end
var q = gs.action.getGlideURI().getMap().get('sysparm_query') + "";
q = q.split("^")
q.filter(function(item){
return item !== 'EQ';
}).map(function(item){
var arr = item.split("=");
var obj = {field: arr[0], value: arr[1]}
gs.log(obj.field + " : " + obj.value + " :list", "ACTION")
})
//q output will be an array of objects of {field: 'name of field', value: 'field value'}