- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2021 11:05 AM
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: "XMLHelper" is not defined. (sys_ws_operation.b35de1cdff0f2010905087f8b721f1cc.operation_script; line 22)</detail><message>"XMLHelper" 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);
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2021 02:45 PM
Hi,
Is the scripted rest API within a custom scope? XMLHelper is only available in the global scope.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2021 06:43 AM
No worries,
Alternatively you can use the XMLDocument2 API within a scoped application.
Please mark my answer helpful & correct to close the thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2021 12:46 PM
Hi
Can you please let me know how did you resolve this issue .
I am getting below error.
I am using Scripted REST API in Scoped application and I am using below code
response.setContentType('application/xml');
var writer=response.getStreamWriter();
var xhelper = new XMLDocument2();
writer.writeString(xhelper.toXMLStr(body1));
{
"error": {
"detail": "TypeError: Cannot find function toXMLStr in object <?xml version=\"1.0\" encoding=\"UTF-8\"?>. (sys_ws_operation.df79514c1bd0b4d0c123a8e3b24bcbd8.operation_script; line 117)",
"message": "Cannot find function toXMLStr in object <?xml version=\"1.0\" encoding=\"UTF-8\"?>."
},
"status": "failure"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2021 10:11 PM
toXMLStr isn't a function of XMLDocument2 as per the docs site
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 09:23 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2021 06:06 AM
What are you trying to achieve? The docs advise to use .toString if you're wanting to stringify the response.