Skip to Content

xsjs 500 internal server error

Hi

I'm trying to create my first XSJS file and when trying to run it I am getting "500 Internal server error"

500.png

Here is the code that I am trying to execute:

itsm.png

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

500.png (32.1 kB)
itsm.png (12.3 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Oct 15, 2019 at 03:01 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.