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