500 Internal Server Error when calling Service now Scripted REST API

RA4
Tera Contributor

Hi I am getting below error when i am trying  to call the scripted REST API with below script. Can someone please verify below script and correct  me if anything wrong.

 

Error: <?xml version="1.0" encoding="UTF-8"?><response><error><detail>ReferenceError: &quot;XMLHelper&quot; is not defined. (sys_ws_operation.b35de1cdff0f2010905087f8b721f1cc.operation_script; line 22)</detail><message>&quot;XMLHelper&quot; is not defined.</message></error><status>failure</status></response>

 

Script. 

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

// implement resource heere
var ShortDesc;
var TOnum = request.pathParams.change_number;
var body = {};

var grTO = new GlideRecord('change_request');
grTO.addQuery('number', TOnum);
grTO.query();
if (grTO.next()) {
body.GroupName = grTO.getDisplayValue('assignment_group');
body.State = grTO.getDisplayValue('state');
}

/* response.setContentType('application/JSON');
var writer = response.getStreamWriter();
writer.writeString(JSON.stringify(body));
*/
response.setContentType('application/xml');
var writer = response.getStreamWriter();
var xhelper = new XMLHelper();
writer.writeString(xhelper.toXMLStr(body));

})(request, response);

 
1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi,

Is the scripted rest API within a custom scope? XMLHelper is only available in the global scope.

View solution in original post

10 REPLIES 10

Kieran Anson
Kilo Patron

Hi,

Is the scripted rest API within a custom scope? XMLHelper is only available in the global scope.

RA4
Tera Contributor

i am not sure. where can we check this setting(custom scope or Global scope) ?

It'll be displayed in the top corner of your SRAPI resource

find_real_file.png

RA4
Tera Contributor

looks like i selected custom scope. i will change to global and test it.

Appreciate it, thanks lot !!