- 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-18-2024 08:10 AM
Hi @abhi56 ,
Try below script
var answer = response.responseXML.documentElement.getAttribute("answer");
var parsedanswer = JSON.parse(answer);
if (parsedanswer.result && parsedanswer.result.short_description) {
var shortDescription = parsedanswer.result.short_description;
alert(shortDescription);
g_form.setValue("short_description", shortDescription);
}
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2024 09:03 AM
Hello @abhi56 ,
Can you try making these changes to your code.
In script include add below lines:
Thanks,
Kps Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 02:36 AM
these are not working @kps sumanth @Anand Kumar P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 02:38 AM
Hello @abhi56 ,
Could you please share what you are getting in log messages and the alerts after making the code changes as I mentioned.