Posts Tagged ‘ssjs’

20 Mar 2013
0

Tip: Understand how to compare values in JavaScript

Hi everyone. In this post I want to point out a not so common way to compare variables and their values in JavaScript.

For many out there, the common way to compare 2 values is to use the == or != operators. If we look at the example below however, you’ll notice an interesting result that is returned:

Example:

var boolFalse = false;

var boolTrue = true;

var myString = “”;

if(boolFalse == 0) //This returns True

if(boolTrue == 1) //This returns True

if(myString == 0) //This returns True

The reason why these values are returning true is because as a default, when using == or !=, JavaScript only compares the values and not their variable types.

If you wanted to perform a strict comparison between 2 variables using their Value as well as Type, then you will need to use === or !==.

Example:

if(boolFalse === 0) //This returns False

if(boolTrue === 1) //This returns False

if(boolTrue !== 1) //This returns True

if(myString === 0) //This returns False

 

I now use this as a Standard when coding in JavaScript. I hope this makes sense.

Happy coding :)

John.

17 Jan 2013
2

XPages Tip: Pass NotesDateTime to the Javascript Date Object

Hi all.

I spent this morning creating a massive SSJS Validation Rule that had to do with Date and Time values that were provided by the User online. I think Date Objects will forever remain my Everest, because I just can’t seem to get it right without wasting hours on it.

In SSJS, the problem with the NotesDateTime Object is that properties like “getDateOnly”, “getTimeOnly” and “getLocalTime” return the values as strings. If you want to compare values, you’re in for a tough time.

Now the Javascript Date Object offers you way more in terms of comparing values. Click here to check an awesome function you can use in your code.

I had a scenario where I was using NotesDateTime Objects to manipulate Date/Time Values, but I wanted to pass these Date/Time Values to the JavaScript Date Object to perform compares, etc. My first attempt failed when I tried to use the “getLocalTime” property of the NotesDateTimeObject:

Note: This example is not best practice, but allows me to show you a function available in SSJS

var date1:NotesDateTime = session.CreateDateTime(“2013/01/17 06:00:00″);

var date2:Date = new Date(date1.getLocalTime());

The above-mentioned will fail because date1.getLocalTime() is an illegal Date value according to the JavaScript Date Object. Having said that, there is an awesome NotesDateTime Method called .toJavaData() that converts the value to a JavaScript Date Object:

var date1:NotesDateTime = session.CreateDateTime(“2013/01/17 06:00:00″);

var date2:Date = new Date(date1.toJavaDate());

From here use you can use the Date Object for comparing Date and Time Values.

I trust this helps :)

John.

19 Dec 2012
5

XPages Query: Strange behavior between partialRefreshGet and Post

Hi all. I hit a very strange issue this morning with my Partial Refreshes. It’s the first time i’ve been faced with this problem. I’m happy to say that I managed to resolve the issue, but I’m a bit confused as to why it was an issue in the first place.

Ok, so I have a button that performs an SSJS Function. It also triggers a Partial Refresh of a Panel in my XPage. This Panel that gets refreshed excludes my Button Bar Panel and for very good reasons. My Button Bar Panel should only be refreshed after the initial Partial Refresh of my other Panel in the XPage.

I do this by adding some CSJS to the onComplete event of my Button that’s triggered. It uses a Remote Service to check a condition, then if that condition is True, it performs a Partial Refresh of the Button Bar Panel. I used a XSP.partialRefreshGet for the partial refresh of the Button Bar Panel.

Now, what I noticed, was that the Button Bar Panel in some cases, was been refreshed before the Primary Partial Refresh. This doesn’t happen in the first 2 times that the button is clicked, but only from the 3rd time onward. I couldn’t understand this because according to Firebug, the Partial Refreshes occur in the correct Sequence.

How I fixed the issue was quite simple: I changed the XSP.partialRefreshGet to a XSP.partialRefreshPost. This immediately resolved the issue and everything works perfectly.

In short, I am just a bit confused as to why a XSP.partialRefreshGet would run its actions out of sequence. Very strange behavior.

Would love some feedback or comments.

 

Cheers

John.

18 Dec 2012
6

XPages Tip: Use postScript to launch Links in own window from SSJS

Hi everyone. I have this 1 project where I need to run a SSJS Function and within it, open a link in a new Window with some parameters.

The best way to do this is to use the postScript Function that belongs to the XPages view Object.

Here’s an example

Let’s say that I wanted to open an XPage in a new window and add some parameters to it:

var myparam = “Test”;

var myurl = @LeftBack(context.getUrl(),”/”) + “/myxpage.xsp?id=”+myparam;

view.postScript(“window.open(‘” + myurl + “‘)”);

As easy as that. Hope this helps :)

Cheers.

18 Sep 2012
3

TUTORIAL: Integrating XPages with DB2 – Part 2

Hi everyone. So, just 2 things firstly:

1. This is an extended Post to David Leedy’s NotesIn9 Posting of “Intro to XPages and Relational Data – Part 2“.

2. I do apologize that this took a while to publish. This is one of the more challenging years to find some free time to contribute to the Domino and XPages community. Having said that, I have quite a few Video Tutorials planned before this year ends, so stay tuned :)

 

Now that that’s out the way…..this post is Part 2 to the “Integrating XPages with DB2 – Part 1“. In this Video I show you how to Create/Read/Update/Delete DB2 Data using XPages. More importantly, I show you how to empower the User to perform all these functions via a User Interface. It’s usually easy to write this logic in the back-end, but a little more involved when handing that power over to the User.

 

The good news is that it’s fairly straightforward. I show you some quick functions that will get you up and running in no time. As I explained in the Video though, there are much more advanced ways of integrating to DB2. This will involve some knowledge of DB2 itself. The keyword is…..”Stored Procedures“. This is where the power lies. A Stored Procedure is very much like a Sub Routine in LotusScript or a Function in Java or JavaScript, but you code in SQL Language. You can pass the Stored Procedure parameters, have all your logic neatly set out in a central place in DB2 and return values from the Stored Procedure which will allow you do things like create Child Documents, etc.

Later on in the near future, I will think up a straightforward Tutorial which will show you how this all works.

I hope you enjoy this Video. I really enjoyed making it. It was one of my smoothest recordings where everything went right the first time.

I want to thank David Leedy as always for adding this to his NotesIn9 Series. You da man :)

Cheers.

John

 

IMPORTANT NOTE: If you are not able to view this Video in HD, please Click Here to open this video up in a different Player.