cancel
Showing results for 
Search instead for 
Did you mean: 

Who Me Too'd this topic

How to Setup Response Pages in using javascript and ajax for Service-Now

L1 Bithead

I'm trying to setup PaloAlto response pages to submit content using "button" to Service-Now.  It seems that in order for content of response page to be 'sent' to Service-Now, javascript and ajax must both be used in the html response page.  My questions are:

 

1) does PaloAlto response pages support ajax?

2) does anyone have an example of submitting content from response page to Service-Now or other ticketing system?

 

Here is code example that I'm working on.

 

<form id = "frm1" action='https://companyname.service-now.com/api/incident' method = "post">
<p>Submit Service-Now ticket for access review.</p><br>
UserName:<br>
<input id= "userID" type="text" name="UserName"><br>
e-Mail:<br>
<input id = "email" type="text" name="e-Mail"><br>
<b>Comment: </b><br>
<textarea id = 'description' cols="50" rows="4" name="Description"></textarea><br>
<input id = "ip" type=hidden name="IP Address" value="<user/>">
<input id = "url" type=hidden name="URL" value="<url/>">
<input id = "pCategory" type=hidden name="PaloAlto Category" value="<category/>">
<input id = "ruleName" type=hidden name="RuleName" value="<rulename/>">
<input id = "snCategory" type=hidden name="SN Category" value="internalADgroup">
<input type=hidden name="Assignment Group" value=&nbsp"internalSNgroup">
<input type=hidden name="SubCategory" value=&nbsp"PaloAlto Gateway">
<input type="reset" value="Reset">
<input type="submit" value"Submit">

 

<script>
function ServiceNowOpenIncident() {
var form = document.querySelector("frm1");
form.addEventListener("submit", function(event) {
console.log("Saving value", form.elements.value.value);
event.preventDefault();
var x = document.getElementById("frm1");
var userID = document.getElementById("userID").value;
var pCategory = document.getElementById("pCategory").value;
var description = document.getElementById("description").value + "<br><strong>" + document.getElementById("ip").name + ":</strong>&nbsp" + document.getElementById("ip").value + ;
var requestBody = "{\"userID\": \"someuser\",\"category\": \"internalSNgroup\",\"subcategory\": \"paloalto_gateway\",\"description\": \"testing form submission to REST Console by ServiceNow\", \"short_description\": \"PaloAlto parked\",\"assignment_group\": \"internalADgroup\"}";
document.getElementById("oms").innerHTML = requestBody;
}
var client=new XMLHttpRequest();
client.open("post","https://companyname.service-now.com/api/incident");

client.setRequestHeader('Accept','application/json');
client.setRequestHeader('Content-Type','application/json');

//Eg. UserName="admin", Password="admin" for this code sample.
client.setRequestHeader('Authorization', 'Basic '+btoa('admin'+':'+'admin'));

client.onreadystatechange = function() {
if (client.readyState === 4 && client.status === 200) {
var json = JSON.parse(client.responseText);
console.log(json.email + ", " + json.password);
};
var data = JSON.stringify(requestBody);
xhr.send(data);
</script>

 

Thanks for reading...

Who Me Too'd this topic