We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Need help for Script include

soumyadaggula
Tera Contributor

Hi Team  , 

am using below catalogue client script to re-direct a catalogue item to Order guide , but I want to write a script include for this , so that it can be used for other order guides also . can you please guide me on how to use this script for Script include .

function onLoad() {
var tstr= top.window.location;
tstr=tstr.toString();
var sstr = "id=sc_cat_item&sys_id";
var ct = -2;
   ct = tstr.indexOf(sstr);  
if (ct != -1) {
top.window.location = "esc?id=sc_cat_item_guide&table=sc_cat_item&sys_id=21470fe11b9601108be4eb53604bcb3a";
 
}
1 ACCEPTED SOLUTION

Ashish37
Mega Guru

Hi @soumyadaggula ,

 

You can do this by creating client callable script include and adding this code to it. you have to use GlideAjax to call that script from you client script. I  tried this and it did worked, you have to pass tstr as a parameter to script include.

.

 

Script include:

 

var Ashish_Catalog_opening = Class.create();
Ashish_Catalog_opening.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    openNewCatalog: function() {
        var tstr = this.getParameter("sysparm_tstr");
        tstr = tstr.toString();
        var sstr = "id=sc_cat_item&sys_id";
        var ct = -2;
        ct = tstr.indexOf(sstr);
        if (ct != -1) {
            return "esc?id=sc_cat_item_guide&table=sc_cat_item&sys_id=0317ba9d47120510f53d37d2846d43bb";

        }
    },

    type: 'Ashish_Catalog_opening'
});
----------------------------------------------
Client script:
function onLoad() {
    //
    var ga = new GlideAjax("Ashish_Catalog_opening");
    var tstr = top.window.location;
    ga.addParam('sysparm_name', 'openNewCatalog'); 
    ga.addParam('sysparm_tstr', "tstr"); 
    ga.getXML(callback);
 
    function callback(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
        top.window.location = answer;
    }
}
 -------------------------------------------------------

 

View solution in original post

7 REPLIES 7

Ashish37
Mega Guru

Hi @soumyadaggula ,

 

You can do this by creating client callable script include and adding this code to it. you have to use GlideAjax to call that script from you client script. I  tried this and it did worked, you have to pass tstr as a parameter to script include.

.

 

Script include:

 

var Ashish_Catalog_opening = Class.create();
Ashish_Catalog_opening.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    openNewCatalog: function() {
        var tstr = this.getParameter("sysparm_tstr");
        tstr = tstr.toString();
        var sstr = "id=sc_cat_item&sys_id";
        var ct = -2;
        ct = tstr.indexOf(sstr);
        if (ct != -1) {
            return "esc?id=sc_cat_item_guide&table=sc_cat_item&sys_id=0317ba9d47120510f53d37d2846d43bb";

        }
    },

    type: 'Ashish_Catalog_opening'
});
----------------------------------------------
Client script:
function onLoad() {
    //
    var ga = new GlideAjax("Ashish_Catalog_opening");
    var tstr = top.window.location;
    ga.addParam('sysparm_name', 'openNewCatalog'); 
    ga.addParam('sysparm_tstr', "tstr"); 
    ga.getXML(callback);
 
    function callback(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
        top.window.location = answer;
    }
}
 -------------------------------------------------------

 

@Ashish37 
Hi Ashish , 
thank you a lot for helping me with the script include , but can I remove the sys ID in the script , and get the sys id for the catalogue item which user is trying to open , and re-direct it to order guide page , with this I can use the same script include for multiple order guides .


@soumyadaggula  Glad I was able to help. yes you can use your sys_id, if its not going to change for sure then you can hard code it in script include like i did OR if you like you can create a system property and call gs.getProperty() to use it.

 

Please accept solution or mark answer if my solution was able to resolve your problem. Thanks!