0
votes

I'm one of the naive developer of XPages application. I took up XPages as I find them really interesting to build whatever we want.

Here is one of my problems on which I am working from days but couldn't get over it.

In my Leave application, I have two date fields, leaveFrom & leaveTill and one computed edit box where I would display the no. of days (noDays) dynamically i.e. the difference of above two leave date fields. And I am unable to do such a simple thing.

I'm using Lotus 8.5.3 for creating this application. I saw some of the methods like getcomponent("").setvalue() or getvalue(). But these two methods are not available in 8.5.3. I always get error when I use these methods. I tried using getComponent on CSJS also.. but no success.

I also tried using other script methods, I could get backend documents created but value is not showing on my current xpage.

Please show me the correct path.

3
Here is a XSnippet which perhaps helps to calculate the duration in business days: openntf.org/XSnippets.nsf/…Sven Hasselbach
You say that you get errors using setvalue and getvalue. Are you trying to use these methods on the CLIENT or the SERVER side? If you try to use them clientside you will fail because these methods are SERVERside javascript.jjtbsomhorst
Thank you Sven. I'm looking at the snippet and try to implement it.Ravi Gupta
@ jjtbsomhorst: I tried using them both on Client as well as Server side JS but none of them worked. Am I missing on any software installation?Ravi Gupta
Practical joke I heard many times: "Repeat after me - Java si CASE SENSITIVE!". And XPages is Java (and JavaScript, which is case sensitive too).Frantisek Kossuth

3 Answers

2
votes

The code is not working because the method timeDifference did not exists for Java dates:

var difference = endDate.timeDifference(startDate);

You have to convert it to NotesDateTime first:

var difference = null; 
try{
    var nDateStart = session.createDateTime( startDate );
    var nDateEnd = session.createDateTime( endDate );

    difference = nDateEnd.timeDifference(nDateStart); 
    difference = (Math.floor(difference/86400)) + 1;
}catch(e){return e}

difference
4
votes

You can use the following XSnippet to compare dates (and thereby also calculate number of days between two dates): http://openntf.org/XSnippets.nsf/snippet.xsp?id=compare-dates. I hope yuou can use this as input for your specific case.

With regards to getComponent("").getValue() and .setValue(). They are certainly available in 8.5.3 too. Remember that XPages is case sensitive.

0
votes

Thanks to your explanatory videos, I learned a lot from them.

Notes in 9? :)

Back to your question.

If both fields are DATETIME format then you can do something like the following.

(endDate - startDate) / (24*60*60);