10-14-2019 1:49 PM - edited 02-04-2024 6:44 AM
Hi
I'm trying to create my first XSJS file and when trying to run it I am getting "500 Internal server error"
Here is the code that I am trying to execute:
var destination_package = "itsm.services";
var destination_name = "Destination";
var custnum = $.request.body.asString();
var essai = custnum.toString().replace("\r", "").replace("\n", "").replace("\t", "");
essai = JSON.parse(essai);
var Prioritytickt = essai.Prioritytickt;
try {
var dest = $.net.http.readDestination(destination_package, destination_name);
var client = new $.net.http.Client();
var req = new $.web.WebRequest($.net.http.GET, "MessageResultSet?$format=json"); //Entity Set
client.request(req, dest);
var response = client.getResponse();
$.response.contentType = "application/json";
var result = response.body.asString();
var jsonResult = JSON.parse(result);
var chatbotResponse;
if (jsonResult.d.results.length > 0) {
if (Prioritytickt === "2") {
chatbotResponse = "Here are the high priority tickets ";
}
if (Prioritytickt === "3") {
chatbotResponse = "Here are the medium priority tickets ";
}
if (Prioritytickt === "4") {
chatbotResponse = "Here are the low priority tickets ";
}
if (Prioritytickt === "All") {
chatbotResponse = "List of all the tickets ";
}
if (Prioritytickt !== "All") {
var ticketdetails = jsonResult.d.results.filter(function(hero) {
return hero.Priority === Prioritytickt;
});
for (var i = 0; i < ticketdetails.length; i++) {
chatbotResponse += ticketdetails[i].ObjectId;
if (i < ticketdetails.length - 1) {
chatbotResponse += ", ";
}
}
} else {
for (var i = 0; i < jsonResult.d.results.length; i++) {
chatbotResponse += jsonResult.d.results[i].ObjectId;
if (i < jsonResult.d.results.length - 1) {
chatbotResponse += ", ";
}
}
}
var output = {
replies: [{
type: 'text',
content: chatbotResponse
}],
conversation: {
memory: chatbotResponse
}
};
}
var body = JSON.stringify(output);
$.response.contentType = 'application/json';
$.response.setBody(body);
$.response.status = $.net.http.OK;
} catch (e) {
$.response.contentType = "text/plain";
$.response.setBody(e.message);
}
Please advice.
Regards,
Florence
Hi ,
You are probably not sending anything to $.request.body.
Since this is not being caught by your try...catch block, your server side script is failing with an internal error.
Try sending something in the request's body to see if it shows up.
Otherwise, I'd recommend enabling XSJS debugging so you can set breakpoints on your code to inspect them before the error has been risen.
Best regards,
Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.