I have the following Google Script that works when executed from a GoogleSheet
function CreateIncident() {
var username = "user";
var password = "Password";
var UserCredentials = "Basic " + Utilities.base64Encode(username + ":" + password)
var IssueURL = "https://xxxx.service-now.com/api/now/v2/table/incident";
var IssueData = {
'short_description':'Description Goes Here',
'priority':'3',
'type':'Normal',
'assignment_group':'Group Goes Here',
};
// Call the API
var payload = JSON.stringify(IssueData);
var headers = { "Accept":"application/json",
"Content-Type":"application/json",
"Authorization": UserCredentials,
};
var options = { "method":"POST",
"headers": headers,
"payload" : payload
};
var response = UrlFetchApp.fetch(IssueURL, options);
if (response.getResponseCode() == 401) {
Browser.msgBox("Error retrieving data for URL" + IssueURL + ":" + response.getResponseCode() + ":" + response.getContentText());
return "";
}
//
// Parse the JSON response to use the Issue Key returned by the API in the email
//
var dataAll = JSON.parse(response.getContentText());
var issueKey = dataAll.number
}
How would this be written in SIL, so that it would execute in Power Script ?
Hello,
I think it would be like this:
struct property {
string property;
string value;
}
struct properties {
property [] properties;
}
struct returnData {
string status;
string issueId;
}
property [] propertyArray;
property p;
properties newIssue;
p.property = "short_description";
p.value = "Description Goes Here";
propertyArray += p;
p.property = "priority";
p.value = "3";
propertyArray += p;
p.property = "type";
p.value = "Normal";
propertyArray += p;
p.property = "assignment_group";
p.value = "Group Goes Here";
propertyArray += p;
newIssue.properties += propertyArray;
string username = "user";
string password = "Password";
HttpRequest request;
HttpHeader header = httpCreateHeader("Accept", "application/json");
request.headers += header;
header = httpBasicAuthHeader(username, password);
request.headers += header;
header = httpCreateHeader("Content-Type", "application/json");
returnData result = httpPost("https://xxxx.service-now.com/api/now/v2/table/incident", request, newIssue);
return result.issueId;
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.