gs.getProperty('glide.servlet.uri') catalog client script - How to get dynamic url of instance

Edxavier Robert
Mega Sage

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");
    }
}

 

 

 

1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

Replace below line in your code:

 

instance.addParam('sysparm_name', 'getUrlDetails');


Raghav
MVP 2023

View solution in original post

10 REPLIES 10

@Edxavier Robert then its not possible, i have provided a link in my previous post.


Raghav
MVP 2023

Thanks, for link.

But If I hard code the instance url into the varible url, I am able to re-direct to the page. What I was trying to do it get the dynamic instance to build the url. 

Ok then probably its an issue with } of function being closed before if block. Close the function } after of block and ot should work.


Raghav
MVP 2023

Hi @RaghavSh ,

Yes, that was the issue, I just move the if condition inside the block and it's working. Here the final code.

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('sysparm_name', 'getUrlDetails');
    instance.getXML(GetUrlPlease);

    function GetUrlPlease(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        
        if (newValue !== 'none') {
            var url = answer + 'sp?id=sc_cat_item&sys_id=' + Sys + '&sysparm_category=69d0e41b1b5f8150a190ece0f54bcb4e',
                _blank;
            top.window.open(url, "_blank");
        }
    }
}

 

Answer is defined inside the GetURLPlease function, you should put the code after that, that needs to act upon answer inside the function.