Agent to create a doculent link

I have a Notes database that stores PO documents, there is then a Mail database with emails that have the subject line with PO Numbers. I am trying to create an agent that runs from the PO database and scans the Mail database for an email that has a subject line that matches the document in the PO database. When it is found it would create a link and save it to the document in the PO database. This would be an automated agent that would run nightly. Does anyone have some code samples, or could point me in the right direction to look?

Thanks,

Subject: A point in the right direction

The steps you need to perform…

Get a collection of the POs (db.search(whatever your criteria,Nothing, 0))

Loop through collection of POs

In a while loop

 dchits = dbMail->search( @contains(subject, PO.PORef),nothing,0)

if (dchits >o) then CreateLink()

…

Depending on the kind of link you want to create (Notes vs URL) do whichever. You may have more than one hit…

PO.Link = whatever

PO.Save

You may want to consider flagging the emails you have linked to so your search criteria does not pick them up twice.

HTH

Subject: RE: A point in the right direction

Great. Thanks for the help.