Connecting app to Java database in JavaScript

Connecting app to Java database in JavaScript

  

Hello,

I am trying to write a simple app that takes a Month (from a static entity) as well as a Day and a Year from Integer Inputs, and returns the day of the week on which the given date occurred.  I have the inputs set up, and I am trying to use Java Script to do the calculation.  The script I am using is as follows.


java.util.Calendar
Calendar c = Calendar.getInstance();
c.setTime(yourDate);
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);


When I try to write this in as a JavaScript in the logic, the system does not recognize any of the Java commands.  How can I link the app to the Java database to get the code to work?

Thanks,

Seamus Herriman

Hi Seamus,

I'm not sure I understand what you are trying to do.

  1. Why are you using JavaScript instead of the OutSystems Platform? There's a built-in DayOfWeek() function.
  2. Do you know the difference between JavaScript (a programming language used mainly* in the browser) and Java (a completely different programming language used in enterprise applications)? It strikes me as very odd that you would think you could use Java code as JavaScript.
  3. What "Java database" are you talking about? What do Java databases have to do with Java calendar functions?

*I'm not going to argue with Node.js proponents. You're evil :)

Kilian Hekhuis wrote:

Hi Seamus,

I'm not sure I understand what you are trying to do.

  1. Why are you using JavaScript instead of the OutSystems Platform? There's a built-in DayOfWeek() function.
  2. Do you know the difference between JavaScript (a programming language used mainly* in the browser) and Java (a completely different programming language used in enterprise applications)? It strikes me as very odd that you would think you could use Java code as JavaScript.
  3. What "Java database" are you talking about? What do Java databases have to do with Java calendar functions?

*I'm not going to argue with Node.js proponents. You're evil :)

Hi Killian,

1. I was not aware that there was a built-in DayOfWeek() function.  I have only just started using OutSystems, and so am still figuring out its intricacies.  Within the interface to create Logics, what component could I add to a Logic to make use of OutSystem's built-in functions?

2.  I was also not aware that JavaScript and Java were completely separate.  I had assumed that JavaScript was a component of Java.  I am by no means highly verses in computer science.  I have taken courses in Java, Python, and MATLAB, but I do not know the relations between these and other languages.

3.  In speaking of a "Java database", I was hypothesizing as to why the Java code I was using in a JavaScript extension was not functioning as expected.  Based on (2), this makes more sense.  At the time, I thought that the code was somehow isolated from a larger system that would read it correctly.  I see now that I was mistaken.

Thank you for your advice.

Seamus


Hi Seamus,

The built-in functions are always included. To use them, when you have the Expression Editor open, in the left lower area there's a tree that starts with "Scope". Below Scope, there's a folder called "Built-in Functions". If you expand that, there's a folder called "Date and Time", and below that, there's the DayOfWeek function. Of course, you can also directly type it in once you know it :). Note that DayOfWeek() starts with Sunday, so if you need a Monday-based day number, you need to adjust for that.

As for the other points, I'd advise you to use Google to get a better overview of the various technologies OutSystems works with (HTML, CSS, JavaScript, Java, .NET, C#, SQL, Oracle, Microsoft SQL Server, SOAP, REST). This will aid you in understanding what goes on behind the scenes.