- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 04:02 PM
Hi all,
I am new to ServiceNow and Scripted REST APIs. I have looked at several resources and have not been successful in getting an answer. I would like my Scripted REST API to return XML. Is this possible? It seems others are only returning XML when using SOAP.
I am able to get the output I want, but not in an appropriate format.
Below is my current Scripted REST Resource Script (Geneva). I want to return all the names of the applications in a table.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var xmldoc = new XMLDocument("<myResponse></myResponse>");
var application = new GlideRecord("cmdb_ci_appl");
application.query();
while (application.next()) {
xmldoc.createElement("application", application.name);
}
return xmldoc.getDocumentElement().toString();
})(request, response);
After editing the script to return XML, below is my response body.
Any help would be very appreciated - thanks in advance.
Hannah
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2016 04:27 AM
Hi Hannah,
I hope below blog will help you find your solution.
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2016 03:39 AM
Yes you can return XML. Do you have access to the REST API explorer? I tried it in the explorer which allows you to choose the format to return. One of your choices is 'application/xml'. Perhaps there is an error in your syntax for creating the xmldoc?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2016 05:10 AM
hannahrobertson Could you please help me understand why you would like to script this particular example in Scriipted RETS api since it can be done wih the standard API directed at the Tables option. It then returns json or xml, whichever your choice. Furthermore, the HTTP method can be taken to a program like Postman and you can get al the information externally with the follwing:
GET https://yourinstancename.service-now.com/api/now/table/cmdb_ci_appl?sysparm_query=&sysparm_fields=name&sysparm_limit=10
You wil need to set up basic authentication or OAuth (and get a token) first.
XML Beautifier takes the output and gives you:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<result>
<name>IronMail-SD-01</name>
</result>
<result>
<name>IronMail-SD-02</name>
</result>
<result>
<name>EXCHANGE-NY-02</name>
</result>
<result>
<name>EXCH-SD-05</name>
</result>
<result>
<name>EXCH-SD-07</name>
</result>
<result>
<name>PS Apache01</name>
</result>
<result>
<name>PS Apache02</name>
</result>
<result>
<name>PS Apache03</name>
</result>
<result>
<name>SAP WEB01</name>
</result>
<result>
<name>SAP WEB02</name>
</result>
</response>
Links:
Postman: Postman | Supercharge your API workflow
XML Beautifier: XML Beautifier
Let me know. If it is for study purposes, then I may catch up with your efforts soon. If I find a solution I will post again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 12:30 PM
Hi Dirk,
This is a simple test, but in the future the data needed will be too complex for the Table API because we will be spanning multiple tables.
I still have not found a solution and might have to choose to go with Scripted SOAP Services instead.
Thank you for your response,
Hannah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2016 12:51 PM
Hi Hannah,
If you are having trouble moving data via SOAP and web services, you might want to take a peek at Perspectium. It'a a native application that allows for code-less data integration.