- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 07:43 AM - edited 02-18-2024 07:45 AM
Hi all I have a requirement like whenever i get the json response from the script include i have fetch the short description value and put it in a variable in a record producer
for that i have created a script include which is fetching the details from 3rd party tool
then i am passing it to the client script
when i am passing the whole response it is working (alert1)
then i try to access the short description it gives error
i tried to use the comminuty post also
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 04:22 AM
Hi @abhi56
Please try with below code. I have tested it on my PDI and it is working as expected :
Script Include -
var test = Class.create();
test.prototype = Object.extendsObject(AbstractAjaxProcessor, {getResponse:function() {
var request = new sn_ws.RESTMessageV2();
//var certi = this.getParameter("sysparm_id"); //please provide here some certificate ID hardcoded for testing
//var certi="baa7af2b935402104ccd73118bba10a0"
request.setEndpoint('https://dev212357.service-now.com/api/now/table/incident' );
request.setHttpMethod('GET');
request.setQueryParameter("sysparm_query","sys_id=baa7af2b935402104ccd73118bba10a0^caller_id=62826bf03710200044e0bfc8bcbe5df1^short_descriptionLIKEabhinandan");
request.setQueryParameter("sysparm_fields","number,short_description");
var user = 'admin'; //provide here user name
var password = 'D55lYs/$tMYm'; //provide here password
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type', 'application/json');
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var jsonResponse= JSON.parse(responseBody);
jsonResponse = jsonResponse.result;
return JSON.stringify(jsonResponse);
},
type: 'test'
});
Client Script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('global.test');
ga.addParam('sysparm_name', 'getResponse');
ga.addParam('sysparm_id', newValue);
ga.getXML(getData);
}
function getData(response) {
try{
var answer = response.responseXML.documentElement.getAttribute("answer");
var parsed = JSON.parse(answer);
var shortDescription = parsed[0].short_description;
g_form.setValue("short_description", shortDescription );
}
catch(e){
alert(e);
}
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 04:22 AM
Hi @abhi56
Please try with below code. I have tested it on my PDI and it is working as expected :
Script Include -
var test = Class.create();
test.prototype = Object.extendsObject(AbstractAjaxProcessor, {getResponse:function() {
var request = new sn_ws.RESTMessageV2();
//var certi = this.getParameter("sysparm_id"); //please provide here some certificate ID hardcoded for testing
//var certi="baa7af2b935402104ccd73118bba10a0"
request.setEndpoint('https://dev212357.service-now.com/api/now/table/incident' );
request.setHttpMethod('GET');
request.setQueryParameter("sysparm_query","sys_id=baa7af2b935402104ccd73118bba10a0^caller_id=62826bf03710200044e0bfc8bcbe5df1^short_descriptionLIKEabhinandan");
request.setQueryParameter("sysparm_fields","number,short_description");
var user = 'admin'; //provide here user name
var password = 'D55lYs/$tMYm'; //provide here password
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type', 'application/json');
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var jsonResponse= JSON.parse(responseBody);
jsonResponse = jsonResponse.result;
return JSON.stringify(jsonResponse);
},
type: 'test'
});
Client Script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('global.test');
ga.addParam('sysparm_name', 'getResponse');
ga.addParam('sysparm_id', newValue);
ga.getXML(getData);
}
function getData(response) {
try{
var answer = response.responseXML.documentElement.getAttribute("answer");
var parsed = JSON.parse(answer);
var shortDescription = parsed[0].short_description;
g_form.setValue("short_description", shortDescription );
}
catch(e){
alert(e);
}
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 06:15 AM
this is working when i am using the setquery aprameter but when i try to pass value from the client scrip to the script include -it is not setting the value again
i tried to use these 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 02:56 AM
Hi @abhi56
You can tweak the script include and client script as below for that :
Script Include -
var test = Class.create();
test.prototype = Object.extendsObject(AbstractAjaxProcessor, {getResponse:function() {
var request = new sn_ws.RESTMessageV2();
//var certi = this.getParameter("sysparm_id"); //please provide here some certificate ID hardcoded for testing
var certi="baa7af2b935402104ccd73118bba10a0";
request.setEndpoint('https://lticoe8.service-now.com/api/now/table/incident/'+ certi );
request.setHttpMethod('GET');
//request.setQueryParameter("sysparm_query","sys_id=baa7af2b935402104ccd73118bba10a0^caller_id=62826bf03710200044e0bfc8bcbe5df1^short_descriptionLIKEabhinandan");
//request.setQueryParameter("sysparm_fields","number,short_description");
var user = 'admin'; //provide here user name
var password = 'D55lYs/$tMYm'; //provide here password
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type', 'application/json');
var response = request.execute();
//gs.info(response.getStatusCode());
//gs.log(response.getBody());
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var jsonResponse= JSON.parse(responseBody);
jsonResponse = jsonResponse.result;
gs.info(JSON.stringify(jsonResponse));
return JSON.stringify(jsonResponse);
//return JSON.stringify(response.getBody());
},
type: 'test'
});
Client Script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('global.test');
ga.addParam('sysparm_name', 'getResponse');
ga.addParam('sysparm_id', newValue);
ga.getXML(getData);
}
function getData(response) {
try{
var answer = response.responseXML.documentElement.getAttribute("answer");
var parsed = JSON.parse(answer);
var shortDescription = parsed.short_description;
g_form.setValue("short_description", shortDescription );
}
catch(e){
alert(e);
}
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.