I recently had a customer ask if there were any way to submit XML data to a service-now instance for processing. My first response was, “Yes! SOAP Web Services”. For some reason, however, their integrating platform was incapable of sending SOAP messages, but it could perform an HTTP Post of XML data.
I played around with a couple of ideas and got a rudimentary method of getting XML into a ServiceNow instance via an HTTPS Post.
The best idea of the ones I tested was to create a UI Page in the ServiceNow system. That UI page could be written so that it looks for a POST parameter that would contain XML. In this example, I chose a post parameter named “myXML”. The UI Page would not be public, so the client would have to authenticate using Basic Authentication.
Here is my UI Page that I created:
The jelly code (as seen in the screenshot) is:
1 2 3 4 5 6 7 8 | <?xml version="1.0" encoding="utf-8" ?> <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"> <g:evaluate> gs.log("SUBMITED XML: " + RP.getParameterValue("myXML")); </g:evaluate> </j:jelly> |
Essentially, I created a tag in the Jelly script called “<g:evaluate>”. This tag tells the Jelly to execute the following server side javascript when the page is rendered/loaded.
Then, I used a global variable in the UI Pages called “RP”. This is an object that contains the HTTP Request information. It has a function called “getParameterValue” that allows me to specific a POST Parameter and get the value for that parameter. In our case, this will be the “myXML” parameter that we are expecting.
Then, I just log that XML to the log file.
Now to test this UI Page, I wanted to create an HTML form that would send a POST of XML data to my Instance. This was a quick a dirty way of letting me play around without creating a client program that sends XML to the instance via HTTP Post. A browser will do it for you quickly enough, as long as the browser is currently authenticated to the instance. So, for testing purposes, here is the html form that I created and saved on my local disk (eg. c:\delme\test.html) to do my testing with:
1 2 3 4 5 6 7 8 9 10 |
Notice that the “action” on my html form points to the UI Page that I created on my instance.
So, when I load my test form and enter in XML data it will look like this on my custom webpage:
When I click “Submit”, the myXML field data will be sent to our UI Page for processing. If you look at the log file after clicking Submit, you will see the following:
As you can see, the full XML value was captured inside of the instance. You could now manipulate the XML to do what you want it to do. Probably the most popular thing to do would be to process the XML via an Import Set as seen on my blog here:
https://john-james-andersen.com/blog/service-now/converting-xml-to-a-record-in-servicenow.html
What is the scope of RP..can it be used in ui actions business rule..what are the available methods. Is it a wrapper class for HTTPRequest?
This is all I know about the “RP” object referenced in this post:
http://wiki.service-now.com/index.php?title=Extensions_to_Jelly_Syntax#RP
I believe it is only available in UI Pages (or other places where Jelly is involved), but I could be wrong.
I hope this helps.
Hi John,
Is the reverse possible? Can we pull the data into Service Now using a GET Response ? Any
pointers?
Thanks!
@Abhiram – Yes, I believe this example works with a GET request as well.
John,
Any example or reference for passing the Basic Authentication, especially with a site using SSO?
I know it’s three years since this post but, ran across a need for this from a legacy system. I already had the WSDL and Transform setup when they realized they couldn’t do SOAP.
Thanks,
Dennis