- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2021 05:42 PM
I am looking for any advice on how to get past this issue.
Function: workspace user opens form menu and selects UI action. The UI action calls a script include that builds a url and passes it back as the response. UI action script then opens the URL in a new tab\window.
Issue: the response in the UI action scrip is always "null"
The UI Action Script:
function onClick(g_form) {
//Debug
alert(g_form.getUniqueValue()); //valadate that script gets called
var ga = new GlideAjax('cpx_gsc_consumer_profile_id_lookup');
ga.addParam('sysparm_name', 'setUserProfileID'); //call script include function
ga.addParam('sysparm_sysID', g_form.getUniqueValue()); //set param for sys_ID for look up
ga.addParam('sysparm_table', "x_cinep_gst_serv_guest_svc_case"); //set param for table
ga.getXML(setURLCallback); //get answer through callback function setURLCallBack
}
var setURLCallback = function(response) {
//get answer from script include response
var answer = response.responseXML.documentElement.getAttribute("answer");
//Debug
alert(answer); //keeps showing up as null
var win = top.window.open(answer, '_blank');
win.focus; //open retrived url in new window and set browser focuse to that window
};
The Script Include:
var cpx_gsc_consumer_profile_id_lookup = Class.create();
cpx_gsc_consumer_profile_id_lookup.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
type: 'cpx_gsc_consumer_profile_id_lookup',
setUserProfileID: function(){
jslog("Lookup: is in setUserProfileID function");
//get passed perams
var my_sysID = this.getParameter('sysparm_sysID');
var my_table = this.getParameter('sysparm_table');
// get url from system property
var baseURL = gs.getProperty("App.Property_Name");
//get GSC record
var gr = new GlideRecord(my_table);
gr.get(my_sysID);
//get consumer profile id
var userProfileID = gr.consumer.user_profile_id;
//build answer (URL)
var profileURL = backStageURL + userProfileID;
return profileURL;
},
});
Not sure what I am missing. my debug steps seem to indicate that the onClick() works as it gets the sys_id of the record. but the debug step in the script include is not getting logged indicating that the script include function is not running. so when my final debug step in the UI action triggers the answer is "null". From what I read if I want to pull any data from a related record using the glideAjax method is the best practice. Not sure I am missing anything, through my research the process is straight forward. create the glideAjax object passing the script include name for the constructor. first param should be sysparam_name which is the function I am calling. Pass any params I want and in the script include function process and return a value. this then gets processed in the getXML() using a callback function to get the answer element that can then be used. Yet clearly I am missing something as I get undefined or null.
Additional details:
1) the script include is set as client callable
2)Script include is set to be accessible from all application scopes
3) while the UI action is in another scope then the script include originally they where in the same scope but kept getting a scope mismatch error so rewrote the script include under the global scope and renamed the old one.
thanks in advance for any ideas or suggestions.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2021 06:47 PM
Hi,
//About your Script Include
I believe that you'd like to write "baseURL" instead of "backStageURL" to build your answer. Well, let's write a simple code just to return something:
var cpx_gsc_consumer_profile_id_lookup = Class.create();
cpx_gsc_consumer_profile_id_lookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setUserProfileID: function() {
//build answer (URL)
var profileURL = 'www.teste.com';
return profileURL;
},
});
Now, let's try to get your answer on the Client Script:
function onLoad() {
var ga = new GlideAjax('cpx_gsc_consumer_profile_id_lookup');
ga.addParam('sysparm_name', 'setUserProfileID'); //call script include function
ga.addParam('sysparm_sysID', g_form.getUniqueValue()); //set param for sys_ID for look up
ga.addParam('sysparm_table', "sys_user"); //set param for table
ga.getXMLAnswer(setURLCallback); //get answer through callback function setURLCallBack
function setURLCallback(response1) {
alert('Callback: ' + response1);
}
}
I used an onLoad() function just to test but I believe you can evolve from here.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2021 06:47 PM
Hi,
//About your Script Include
I believe that you'd like to write "baseURL" instead of "backStageURL" to build your answer. Well, let's write a simple code just to return something:
var cpx_gsc_consumer_profile_id_lookup = Class.create();
cpx_gsc_consumer_profile_id_lookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setUserProfileID: function() {
//build answer (URL)
var profileURL = 'www.teste.com';
return profileURL;
},
});
Now, let's try to get your answer on the Client Script:
function onLoad() {
var ga = new GlideAjax('cpx_gsc_consumer_profile_id_lookup');
ga.addParam('sysparm_name', 'setUserProfileID'); //call script include function
ga.addParam('sysparm_sysID', g_form.getUniqueValue()); //set param for sys_ID for look up
ga.addParam('sysparm_table', "sys_user"); //set param for table
ga.getXMLAnswer(setURLCallback); //get answer through callback function setURLCallBack
function setURLCallback(response1) {
alert('Callback: ' + response1);
}
}
I used an onLoad() function just to test but I believe you can evolve from here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2021 06:08 AM
I apologize,
backStageURL was left in by error as I was sanitizing the the variable names and missed the line.
however I was able to resolve the issue although not sure why it is working now. using your methodology started over with a simple test url to validate and built the rest around it.
thank you