@If or if condition

I have the following code in a xpage postSaveDocument event. It works fine.

var db:NotesDatabase = session.getDatabase(session.getServerName(), “TimeOffxp.nsf”);

var agent:NotesAgent = db.getAgent;

agent.runOnServer(dominoDocument1.getNoteID());

Now, I want to add a condition so it only run when it is a new document. I tried the following codes and none of them seems work for me.

(1)

var db:NotesDatabase = session.getDatabase(session.getServerName(), “TimeOffxp.nsf”);

var agent:NotesAgent = db.getAgent;

@If(@IsNewDoc()==1,agent.runOnServer(dominoDocument1.getNoteID()));

(2)

var db:NotesDatabase = session.getDatabase(session.getServerName(), “TimeOffxp.nsf”);

var agent:NotesAgent = db.getAgent;

if(@IsNewDoc()==1){

agent.runOnServer(dominoDocument1.getNoteID());

}

Please advise what are the correct ways/formats to set if condition in xpage. Thanks.

Subject: Re @If or if condition

I see my problem that the code is in postSaveDocument event. So @IsNewDoc() is not equal to 1. However, if I put the code in querySaveDocument event, I cannot save the document (no error and stay on same page)

Subject: viewScope variable

How about setting a viewScope scoped variable in the querySave event for whether or not it’s a new document, and then referencing that in the PostSave event?

It’s well worth reading this, if you haven’t come across it, to see how to debug scoped variables:

Regards

Paul