JavaScript Question

I am attempting to re-write some lotusscript code in Javascript for use on the web. I have a timesheet form that takes the date & payroll number to build a key and check for a duplicates. I am trying to put the code in a function in a JS Header, but I’m missing something called a Before statement. Can someone please take a look at this code and tell me what am I doing wrong?

Thanks Orlando

function check4duplicate() {

var payrollnum=document.forms[0].payrollnum;

var wkend=document.forms[0].weekend;

paykey=wkend+payrollnum;

// Database db = agentContext.getCurrentDatabase();

view view = db.getview(“timepay”);

Document dupdoc=view.getdocumentByKey(paykey, false);

if (doc != numm)

   alert("A timesheet already exist for this date");

   } catch(Exception e) {

   e.printStacTrace()

   }

Subject: JavaScript Question

Hi Orlando,

You can’t use Lotuscript code into javascript:

view = db.getview(“timepay”);

dupdoc=view.getdocumentByKey(paykey, false);

To use Lotuscript over the web you must use an agent.

also if “payrollnum” and “weekend” are fields, you must use document.forms[0].payrollnum.value (append .value) to retrieve field value.

but you can make this with an @Dblookup/computed text/HTML passthru to make that, something like this:

(I suppose that payrollnum and weekend are notes fields)

HTH

Thierry

Subject: JavaScript Question

You are confusing two completely different languages – JavaScript and Java. They are most definitely not related. The error message you are getting is:

Missing ; before statement

(with a line number), which is telling you that the Java statements using the Database, View and Document data types are not valid JavaScript.

If you want to do a lookup check before the form is submitted on the web, you will need to investigate means of making additional browser requests to the Domino server – particularly, a set of technologies collectively called AJAX. (There are non-AJAX methods as well, such as using IFRAMEs and pop-unders, but AJAX solutions are generally “cleaner”.) There are several examples here on this forum, but you’re going to have to do a little bit of background research first to get from your current level of knowledge to a point where you can comfortably use AJAX.

Subject: JavaScript Question

Orlando,

If you know Java I would recommend you write it in a Java library.

Then you can reuse that library anywhere in notes. You can use it in forms, agents whatever. if you don’t know Java, it seems like you know LS, so just move your validation to a LS library and add the function calls to an agent you create and call in the WebQuerySave event.

That way you can reuse that LS code everywhere.

We do this quite frequently in one app in particular. If you need a hand, I can help. My email is in my profile.

As to the question(s) you ask, here are some observations.

function check4duplicate()

{

// session variables

var payrollnum = document.forms[0].payrollnum;

var wkend = document.forms[0].weekend;

var paykey = wkend + payrollnum;

view view = db.getview(“timepay”); // ‘View’ is a Java data type for a notes view, it’s not a JS data type that I know of

// Database db = agentContext.getCurrentDatabase();

Document dupdoc=view.getdocumentByKey(paykey, false);

// ‘Document’ is a Java data type for a notes Document, it’s not a JS data type that I know of.

if (doc != numm) // doc is a null variable as it was never declared or instantiated above

// alert is a javascript function, you seem to be trying to mix Java and JavaScript, they are different.

alert(“A timesheet already exist for this date”);

}

// Is there a Try that this catch is associated with?

catch(Exception e)

{

e.printStacTrace() // Typo - should be ‘e.printStackTrace()’

}

Shawn