- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2015 11:05 AM
We are moving New Calls to Requests and need to include description and short description in the URL that opens up a Request Item. Reserved and unsafe characters are stopping the URL from processing properly. What is the correct way to script the encoding of the URL?
Here is what I've tried. This is from the business rule called "CallTypeChanged to Request"
1. When I try to encode the entire URL I get a message telling me it can't find the page.
var reqFor = current.caller;
var location = current.caller.location;
var reqItem = current.request_item;
var desc = current.description;
var sdesc = current.short_description;
var comments = "NEW_CALL_REF:"+current.sys_id+" "+current.description;
var url = encodeURIComponent('com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqItem + '&sysparm_user=' + reqFor + '&sysparm_location=' + location + '&sysparm_comments=' + comments + '&sysparm_description=' + desc + '&sysparm_short_description=' + sdesc);
2. When I try to encode portions of the URL, the rest of the URL doesn't transfer properly from the New Call to the Request. The encoded portions do transfer properly. But I need location and requester, and they come over as "undefined". And when I encode them, they still come over to the request item as undefined.
var reqFor = current.caller;
var location = current.caller.location;
var reqItem = current.request_item;
var desc = current.description;
var sdesc = current.short_description;
var comments = "NEW_CALL_REF:"+current.sys_id+" "+current.description;
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqItem + '&sysparm_user=' + reqFor + '&sysparm_location=' + location + '&sysparm_comments=' + comments + &sysparm_description=' + encodeURIComponent(desc) + '&sysparm_short_description=' + encodeURIComponent(sdesc);
3. When I try to encode the variable data and then place it in the URL, the data doesn't transfer.
var reqFor = current.caller;
var location = current.caller.location;
var reqItem = current.request_item;
var desc = encodeURIComponent(current.description);
var sdesc = encodeURIComponent(current.short_description);
var comments = "NEW_CALL_REF:"+current.sys_id+" "+current.description;
var url ='com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqItem + '&sysparm_user=' + reqFor + '&sysparm_location=' + location + '&sysparm_comments=' + comments + '&sysparm_description=' + desc + '&sysparm_short_description=' + sdesc;
Any help here would be greatly appreciated.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2015 11:46 PM
This works and the parameter get's passed
gs.setRedirect("com.glideapp.servicecatalog_cat_item_view.do?&sysparm_id=c9e2388a0fe23100781ccf8ce1050e96&sysparm_call_id=" + current.sys_id);
Now read the data from the URL using
decodeURI(document.URL.parseQuery()['sysparm_call_id'])
Use the sys id, query the table and get the call details needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2015 01:36 PM
Kalai,
Thanks so much for your help. Your answer worked great, with a couple of changes. The gs.setRedirect() didn't work to open the RITM from the CALL, so I went back to the old way of doing the URL, as you see below.
Here is the Business Rule ("CallTypeChanged to Request"). I opted to leave the location in since that wasn't working in the onLoad() script, and this will never be a burden on the 1024 character limit in IE. In case we ever want to use the "Special Instructions" field, I left that one intact as well. We don't show that field now on any of our forms.
var location = current.caller.location;
var reqItem = current.request_item;
var comments = "NEW_CALL_REF:"+current.sys_id+" "+current.description;
getCart();
var url = 'com.glideapp.servicecatalog_cat_item_view.do?&sysparm_id=' + reqItem + '&sysparm_call_id=' + current.sys_id + '&sysparm_location=' +location;
action.setRedirectURL(url);
function getCart() {
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
// We already have a cart so override the requested for value and empty it
cart.requested_for = reqFor;
cart.special_instructions = comments;
cart.delivery_address = getDeliveryAddress();
cart.update();
var cartItems = new GlideRecord('sc_cart_item');
cartItems.addQuery('cart', cart.sys_id);
cartItems.deleteMultiple();
} else {
cart.initialize();
cart.user = userid;
cart.requested_for = reqFor;
cart.special_instructions = comments;
cart.delivery_address = getDeliveryAddress();
cart.insert();
}
return cart;
}
function getDeliveryAddress() {
var gr = new GlideRecord('cmn_location');
if (!gr.get(location))
return '';
var text = '';
if (!gr.street.nil())
text = gr.street + '\n';
if (!gr.city.nil() && !gr.state.nil() && !gr.zip.nil())
text += gr.city + ", " + gr.state + ", " + gr.zip;
return text;
}
And here is the onLoad() Catalog Client Script with the query to the New Call table. The only thing I need to figure out is how to NOT run the script if this isn't coming from a new call (2 fields populate as undefined when I do that), but it's very minor in the grand scheme of things.
function onLoad() {
var callid = decodeURI(document.URL.parseQuery()['sysparm_call_id']);
var loc = decodeURI(document.URL.parseQuery()['sysparm_location']);
var getcallinfo = new GlideRecord('new_call');
getcallinfo.addQuery('sys_id', callid);
getcallinfo.query();
while (getcallinfo.next()) {
var desc = getcallinfo.description;
var sdesc = getcallinfo.short_description;
var req = getcallinfo.caller;
}
g_form.setValue('description',desc);
g_form.setValue('short_description',sdesc);
g_form.setValue('requester', req);
g_form.setValue('location',loc);
}
function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
}
else{
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2015 01:30 AM
Just add a undefined check as below.(Test it once)
var callid = decodeURI(document.URL.parseQuery()['sysparm_call_id']);
var loc = decodeURI(document.URL.parseQuery()['sysparm_location']);
if(typeof callid != 'undefined' && typeof loc != 'undefined')
{
rest of code
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2015 07:46 AM
Perfect.
Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2015 09:00 AM
Actually, the typeof code didn't work, so I added a parameter to the URL to throw the word "yes" over to the request. When I check for that it works great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2019 02:33 PM
Thanks for this post it has been very helpful in helping me solve an issue we have. Would you mind telling me how you added the yes to your URL and how you wrote your if statement in your catalog client script to look for it?
Thanks