- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 09:02 AM
Hi, I have catalog client script where I need to get the dynamic URL of the current instance. I was reading that I need to create a script include and use a GlideAjax to call it. But is returning null. So far this is what I got.
Script Include
Client callable is set to true
var GetURL = Class.create();
GetURL.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUrlDetails: function() {
var instanceURL = gs.getProperty('glide.servlet.uri');
return instanceURL;
},
type: 'GetURL'
});
Catalog client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var Sys = g_form.getValue('software_items');
var instance = new GlideAjax('GetURL');
instance.addParam('sysparam_name', 'url');
instance.getXML(GetUrlPlease);
function GetUrlPlease(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
if (newValue !== 'none') {
var url = answer + 'sp?id=sc_cat_item&sys_id=' + Sys + '&sysparm_category=69d0e41b1b5f8150a190ece0f54bcb4e',
_blank;
top.window.open(url, "_blank");
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 09:25 AM
Replace below line in your code:
instance.addParam('sysparm_name', 'getUrlDetails');
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 09:25 AM
Replace below line in your code:
instance.addParam('sysparm_name', 'getUrlDetails');
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 09:44 AM
Hi @RaghavSh,
That work! Now I am getting the correct URL in the alert message that I have, but I am unable to get re-directed. I had a JavaScript error - 'ReferenceError: answer is not defined'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 09:54 AM - edited 12-09-2022 10:01 AM
Are you working on portal? If yes window object is not accessible on portal.
Please mark the answer correct/helpful accordingly.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 10:01 AM
Yes, I am working on the Service Portal.