Agent code check/help

I have 5 agents that I am transferring over. 1 works, 1 works wrong and 3 of them aren’t working. They are designed to email users to notify them that something is due or overdue.

Agent 2 runs no matter what but is designed to run when the form is due for attention that day.

Agent 2

SELECT Form = “CRECORD”;

@If(NxtCal != @Today & CalDone != “”; @Return(“”);“”);

server := @Subset(@DbName; 1);

Dbname := @LeftBack(@Subset(@DbName; -1); @RightBack(@Subset(@DbName; -1); “\”)) +

“QS4PARTS.NSF”;

View := “Lookup1”;

@If(txtSiteCode = @Trim(@DbLookup(“”; server :DbName; View; “Address”; 11)); “”; @Return(“”));

REM {send the notification message};

@MailSend(CalMgr; @If(LastEditor != From;

@Trim(@Unique(From : LastEditor : Owner));

@Trim(@Unique(LastEditor : Owner))); “”; "Calibration Due. Number: " + ContNum;

“This calibration record shows that it is due for calibration. This equipment must be calibrated or taken out of service. Use the attached document link below to open and view the record.” + @NewLine + "Equipment: " + Subject + @NewLine + "Date Due: " + @Text(NxtCal) + @NewLine + @NewLine + “Regards, Calibration Management.”; “”; [IncludeDoclink]);

@Success

Agent 3, 4 and 5 don’t run at all when tested and are designed to run after the form is overdue at different time periods if i remember right. Not sure what the time periods are though.

Agent 3

SELECT Form = “CRECORD”;

REM; “if the calibration is complete, then do not run on this document”;

@If(CalDone = “”; “”; @Return(“”));

REM; “get the escalation information”;

server := @Subset(@DbName; 1);

Dbname := @LeftBack(@Subset(@DbName; -1); @RightBack(@Subset(@DbName; -1); “\”)) + “QS4PARTS.NSF”;

View := “Lookup1”;

@If(txtSiteCode = @Trim(@DbLookup(“”; server : DbName; View; “Address”; 11)); “”; @Return(“”));

edate := @TextToNumber(@DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 7));

@If(NxtCal = @Adjust(@Today; 0; 0; -edate; 0; 0; 0); “”; @Return(“”));

def := @DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 3);

escal := @DbLookup(“”; server : DbName; View; “Escalation Name”; 2);

@MailSend(def; @Trim(@Unique(CalMgr : LastEditor : Owner)); escal; "Calibration First Escalation Message Number: " + ContNum; “This calibration record shows that it is overdue for calibration. This equipment must be calibrated or taken out of service. Use the attached doc link below to open and view the record.” + @NewLine + "Equipment: " + Subject + @NewLine + "Date Due: " + @Text(NxtCal) + @NewLine + @NewLine + “Regards, Calibration Management.”; “”; [IncludeDoclink]);

@Success

Agent 4

SELECT Form = “CRECORD”;

@If(CalDone = “”; “”; @Return(“”));

server := @Subset(@DbName; 1);

Dbname := @LeftBack(@Subset(@DbName; -1); @RightBack(@Subset(@DbName; -1); “\”)) +

“QS4PARTS.NSF”;

View := “Lookup1”;

@If(txtSiteCode = @Trim(@DbLookup(“”; server : DbName; View; “Address”; 11)); “”; @Return(“”));

edate := @TextToNumber(@DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 8));

@If(NxtCal = @Adjust(@Today; 0; 0; -edate; 0; 0; 0); “”; @Return(“”));

def := @DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 3);

def1 := @DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 4);

escal :=@DbLookup(“”; server : DbName; View; “Escalation Name”; 2);

@MailSend(def1; @Trim(@Unique(def : CalMgr : LastEditor : Owner)); escal; "Calibration Second Escalation Message. Number: " + ContNum; “This calibration record shows that it is overdue for calibration. This equipment must be calibrated or taken out of service. Use the attached doc link below to open and view the record.” + @NewLine + "Equipment: " + Subject + @NewLine + "Date Due: " + @Text(NxtCal) + @NewLine + @NewLine + “Regards, Calibration Management.”; “”; [IncludeDoclink]);

@Success

Agent 5

SELECT Form = “CRECORD”;

@If(CalDone = “”; “”; @Return(“”));

server := @Subset(@DbName; 1);

Dbname := @LeftBack(@Subset(@DbName; -1); @RightBack(@Subset(@DbName; -1); “\”)) +

“QS4PARTS.NSF”;

View := “Lookup1”;

@If(txtSiteCode = @Trim(@DbLookup(“”; server : DbName; View; “Address”; 11)); “”; @Return(“”));

edate := @TextToNumber(@DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 9));

@If(NxtCal = @Adjust(@Today; 0; 0; -edate; 0; 0; 0); “”; @Return(“”));

def := @DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 3);

def1 := @DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 4);

def2 := @DbLookup(“”; server : DbName; View; “Escalation Calibration Record”; 5);

escal :=@DbLookup(“”; server : DbName; View; “Escalation Name”; 2);

@MailSend(def2; @Trim(@Unique(def1 : def : CalMgr : LastEditor : Owner)); escal; "Calibration Third Escalation Message. Number: " + ContNum; “This calibration record shows that it is overdue for calibration. This equipment must be calibrated or taken out of service. Use the attached doc link below to open and view the record.” + @NewLine + "Equipment: " + Subject + @NewLine + "Date Due: " + @Text(NxtCal) + @NewLine + @NewLine + “Regards, Calibration Management.”; “”; [IncludeDoclink]);

@Success

Any help would be appreciated

Subject: Agent code check/help

It’s this line:

@If(NxtCal != @Today & CalDone != “”; @Return(“”);“”);

It should probably read:

@If(@Date(NxtCal) = @Today & CalDone = “”; “”; @Return(“”));

You could also fix it by replacing the & with a | in the original. The logic is easier to read, though, if you test for the “go” condition instead of the “no go” in this case, and easier to read/maintain is almost always better.

Subject: RE: Agent code check/help

Thanks!

I changed the & to | and it worked. can you tell me the difference between the & and | since this is foreign to me?

Now to get the other 3 agents to run…

Subject: RE: Agent code check/help

Sure. The & means that both parts have to be true for the whole to be true, and | means that only one or the other needs to be true. In the original statement:

@If(NxtCal != @Today & CalDone != “”; @Return(“”);“”);

you are saying that the “stop processing” condition occurs ONLY when the NxtCal date is not today AND CalDone is not empty. That means the agent will process documents that are due today and have an empty CalDone, which is what you wanted. But it will also process documents that are not due today that have an empty CalDone (which would be just about all of the documents due in the future, along with any overdue docs), or that are due today and have a non-empty value in CalDone (documents the user has already attended to). When you use the OR operator:

@If(NxtCal != @Today | CalDone != “”; @Return(“”);“”);

both of the unwanted conditions that currently trigger processing will return true. Again, I find it more readable in this case to test for the “please process” condition:

@If(NxtCal = @Today & CalDone = “”; “”; @Return(“”));

which much more clearly staes “if the document is due today and hasn’t been marked done, process, else stop processing”.

Subject: RE: Agent code check/help

Thank You. More understandable now.

This may sound dumb but can you tell me what language this is? I have done searches but can’t identify this language. I know you can use various languages. Unless cause this is from version 5 is why I can’t find anything on it.

Subject: RE: Agent code check/help

It’s Notes Formula Language, which derives its syntax from the original Lotus 1-2-3 Formula Language. You won’t find much information on the language outside of the Notes world (since it only exists inside). Conceptually, it has a lot in common with APL (in that it is an array-oriented language, but with verbose function names instead of APL’s single-character Iverson function notation) – and that won’t be a lot of help either, since the APL community has something in the neighbourhood of eight active members.

The language may look weird, but it is immensely powerful and expressive once you wrap your mind around it. There are some things that it can’t do (or can’t do easily), but when it’s the appropriate choice it can save you literally hundreds, even thousands, of lines of code when compared to LotusScript (a variant of Visual Basic) or Java.

Subject: RE: Agent code check/help

Thanks for all your help.

http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=/com.ibm.help.domino.designer85.doc/DOC/H_NOTES_FORMULA_LANGUAGE.html

I found this and am using it to read the code to see what it is saying. So far it is pretty helpful. Alot of work going back and forth but interesting. How much different is the code between 5 that all of my code is from and 8? Anything that maybe changed or was removed that might be in my code?

Also you are saying this is better to use/learn then LotusScript or Java? Or is it limited in what it can do? What is the standard that developers are using currently to create forms, views and agents?

Subject: RE: Agent code check/help

It’s not an either/or choice – there are some parts of Notes that can only be programmed using Formula Language (view selections and column formulas, field-level input enables, setting HTTP headers in web apps, for instance) and some that are a boatload easier in Formula Language than in other languages. Formula Language has grown a few new features since R5, notably looping structures (@For and @While, for instance), and allows larger intermediate data sets, but the language is backwards (and bugwards) compatible with all previous versions. That is, there may be a better way to do it and there may be ways to do what used to be impossible, but the old way will always work.

LotusScipt, you will find, is indispensible – it allows a different interaction model with collections of documents, it can be used to effectively intercept UI events, and it provides a richer set of tools to create, read and write to documents. (LS may also be used to programmatically create and modify Notes design elements.)

Java, on the other hand, is restricted to back end (non-UI) operations. For many tasks, the choice between LS and Java is a matter of programmer preference, but there is a lot in the core Java classes that make it extremely useful for interacting with external data sources and applications safely in a cross-platform environment (things will work whether the OS is Windows, Linux or what have you), and there are packages available that can let you create all sorts of files without having to have the normal host application available. Java is currently a nice-to-have option, but with Notes running on an Eclipse-based platform, Java may become a more important resource in the future.

JavaScript is a web essential and very useful (if a pain to figure out) in the client. If the new xPages design element in Domino 8.5 is any indication, though, there just may be a chance that JS might become a very important scripting language in the Notes client environment as well.