Help with code

Hi,

My knowledge of LotusScript is minimal so I would really appreciate a little help designing an agent to do the following.

I have created a Consumables Inventory database mainly to track the usage the firm’s toner, ink and ribbon cartridges. There is a view that gets populated when items are due to be reordered. It has the following columns:

Col 1: Item Category (Categorized)

Col 2: Item Type (Categorized)

Col 3: Item Name

Col 4: Qty in stock

Col 5: Reorder Point

Col 6: Max Qty

Col 7: Qty to order (formula = MaxQty - QtyInStock) Col totaled

I want an agent to run, say every Monday, which will check that the total quantity of items to be ordered is 5 or more. And if true, then send an email notification to person as a reminder to order the items.

Thanks in advance

Subject: Help with code

Suggest you at least TRY first :wink:

Here’s a rough idea:

Get the NotesView

Create a NotesViewEntryCollection based on the AllEntries property

Loop though the documents in the viewEntry collection using

Do until entry is nothing

…

get the notes document here and find the quantity.

add it to a variable that you have created to hold the accumulated quantity.

…

Set entry=ventrycol.getNextEntry(entry)

Loop

Test the total quantity

If trigger, then create a document with :

form =Memo

SendTo=E-mail Addres

Subject= mail subject

Body=rtitem with your message content.

I would personnally use a NotesNewsletter object to create an e-mail that contains links to all the documents awaiting order.

HTH

Subject: RE: Help with code

Actually, I have been trying for the last two weeks and have simply given up. Like I said, my knowledge of LotusScript is VERY minimal. I will try what you have suggested but I am sure I will be back for more help.

Thanks

Subject: Help with code

I just feel like coding something other than the stuff I am working on at the moment, so here is a try without testing:

I put some comments in the beginning of the code for your information.

Sub Initialize

%REM

Items you might want to notice below:

This requires a profile document called “Config” with a field called “OrderPoint”

This requires a view called “InventoryItems”…a flat view…no categories

This requires a group called “Purchasing”… you can change that to a persons name or

you could add a field to the Config document called something like “ReorderClerk” or something

If you did that, you would use the other line that I remarked out

I think this will work for you as a starting point.

%END REM

Dim s As New NotesSession

Dim db As NotesDatabase

Dim profile As NotesDocument, doc As NotesDocument, memo As NotesDocument

Dim orderpoint As Integer, counter As Integer

Dim view As NotesView

Dim item As NotesItem

Dim rti As NotesRichTextItem

Set db = s.CurrentDatabase

Set view = db.GetView("InventoryItems")

Set profile = db.GetProfileDocument("Config")

orderpoint = profile.OrderPoint(0)



counter = 0



Set memo = db.CreateDocument

memo.form = "Memo"

memo.SendTo = "Purchasing"

'memo.SendTo = profile.ReorderClerk(0)

memo.Subject = "Items need reordering"

Set rti = New NotesRichTextItem(memo, "Body" )

Call rti.AppendText("The following items need to be reordered:")

Call rti.AddNewline(2)	



Set doc = view.GetFirstDocument

Do While Not(doc Is Nothing)

	If doc.QtyInStock(0) <=orderpoint Then

		counter = counter + 1

		Call rti.AppendText(doc.ItemType(0) + " : " + doc.ItemName(0))

		Call rti.AddNewline(1)			

	End If		

	Set doc = view.GetNextDocument(doc)

Loop



If counter = 0 Then Exit Sub



Call memo.Send(False)

End Sub

Subject: Hey, I think you’re onto something…

Everybody gets bored doing the same thing every day; we all like a challenge.

What if…

We all just swapped problems/projects for a month?

This’d be great especially for those of us who work in smallish shops where we tend to keep repeating the same design frameworks. Everybody would get something new to chew on and in return, see how somebody else would think about and solve their problems.

Most posts here are ‘why doesn’t this code work’. I’d love to see more ‘how would you attack this problem’ kind of thing - it forces you to think more broadly and if enough people got involved, might help stimulate new ways of looking at issues.

While you’re at it…got any code for world peace? :wink:

Signed looking for more work…

(and tongue only slightly in cheek)

Doug