- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 12:33 PM
the script include is:
var RL_WkeyLinkDetails = Class.create();
RL_WkeyLinkDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
callRLapi : function(wkey){
var r = new sn_ws.RESTMessageV2('RL_rldbApi', 'Get_WkeyLinkDetails');
midserver = gs.getProperty('mid.server.rba_default');
r.setMIDServer(midserver);
r.setStringParameter('code',wkey);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var res= JSON.parse(responseBody);
var res1= JSON.stringify(res);
if(res.length>0){
alert("Do you want to update the site map link of :"+ wkey +":"+res[0].shortDesc);
} else{
alert(" please enter a valid wkey");
}
},
type: 'RL_WkeyLinkDetails'
});
i want to call this script include from catalog client script and pass the wkey parameter value from input value of catalog request field value.
catalog client script is:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var wkey = g_form.getValue('ux_wkey') ;//geeting variable value
var ga = new GlideAjax('RL_WkeyLinkDetails'); // SI Name
ga.addParam( 'sysparm_name', 'callRLapi'); // Function Name
}
i am not getting an idea how to pass wkey parameter for callRLapi function.
please help..
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2019 06:28 AM
Hi Pavani,
Your script include and catalog client script looks incorrect; please correct it as below
Script Include: Corrections
1) you need to call API and only send the response body from the function
2) you need to get the wkey using this.getParameter() terminology
var RL_WkeyLinkDetails = Class.create();
RL_WkeyLinkDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
callRLapi : function(){
// this is how you get the value passed from client script
var wkey = this.getParameter('sysparm_wkey');
var r = new sn_ws.RESTMessageV2('RL_rldbApi', 'Get_WkeyLinkDetails');
midserver = gs.getProperty('mid.server.rba_default');
r.setMIDServer(midserver);
r.setStringParameter('code',wkey);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
return responseBody;
},
type: 'RL_WkeyLinkDetails'
});
Catalog Client Script Corrections:
1) send sysparm_wkey with the form value
2) parse the json response body returned from the script include function
catalog client script is:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var wkey = g_form.getValue('ux_wkey') ;//geeting variable value
var ga = new GlideAjax('RL_WkeyLinkDetails'); // SI Name
ga.addParam('sysparm_name', 'callRLapi'); // Function Name
ga.addParam('sysparm_wkey', wkey); // send the value to script include function
ga.getXML(getValue);
}
function getValue(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var parsedData = JSON.parse(answer);
// parse the json and set the value wherever required
// parse for url, short description, app ID
// use g_form.setValue() to set the values
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 12:41 PM
Hi,
Please reference this cheat sheet to accomplish what you need: https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...
You also need to make your script include "client callable" as well.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2019 02:22 PM
Hi,
I'm glad you found an answer your question. The overarching issue is that you aren't aware of how to use GlideAjax...please still reference the link I provided. It's nice for the other user to literally give you all the code to use, but you don't learn anything.
Take care!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2019 06:28 AM
Hi Pavani,
Your script include and catalog client script looks incorrect; please correct it as below
Script Include: Corrections
1) you need to call API and only send the response body from the function
2) you need to get the wkey using this.getParameter() terminology
var RL_WkeyLinkDetails = Class.create();
RL_WkeyLinkDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
callRLapi : function(){
// this is how you get the value passed from client script
var wkey = this.getParameter('sysparm_wkey');
var r = new sn_ws.RESTMessageV2('RL_rldbApi', 'Get_WkeyLinkDetails');
midserver = gs.getProperty('mid.server.rba_default');
r.setMIDServer(midserver);
r.setStringParameter('code',wkey);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
return responseBody;
},
type: 'RL_WkeyLinkDetails'
});
Catalog Client Script Corrections:
1) send sysparm_wkey with the form value
2) parse the json response body returned from the script include function
catalog client script is:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var wkey = g_form.getValue('ux_wkey') ;//geeting variable value
var ga = new GlideAjax('RL_WkeyLinkDetails'); // SI Name
ga.addParam('sysparm_name', 'callRLapi'); // Function Name
ga.addParam('sysparm_wkey', wkey); // send the value to script include function
ga.getXML(getValue);
}
function getValue(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var parsedData = JSON.parse(answer);
// parse the json and set the value wherever required
// parse for url, short description, app ID
// use g_form.setValue() to set the values
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2019 10:26 AM
Thanks Ankur for Your response.
i am getting error in script message while executing the g_form.setValue statement.
this is script include:
var RL_WkeyLinkDetails = Class.create();
RL_WkeyLinkDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//callRLapi : function(wkey){
callRLapi : function(){
var wkey = this.getParameter('sysparm_wkey');
var lang=this.getParameter('sysparm_lang');
var r = new sn_ws.RESTMessageV2('RL_rldbApi', 'RL_WKeylinkdetails');
midserver = gs.getProperty('mid.server.rba_default');
r.setMIDServer(midserver);
r.setStringParameterNoEscape('userKey', wkey);
r.setStringParameterNoEscape('languagueCode', lang);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
return responseBody;
},
type: 'RL_WkeyLinkDetails'
});
catalog client script
please help..