Agent Help Please!

Hello, I hope someone can help me here.

I have been working on an application where each document needs to have a sequential reference.

I have 2 views to do this, one which acts as a counter (sequential) and the other which lists unreferenced documents. (unallocated)

Problem being that it is a scheduled agent and all works OK, until for some reason, documents start getting the same number.

e.g. currently up to 45, creat 5 more and next time the agent runs, it will give them all 46.

When I look into each document, of the 5 new documents, it appears the field value in “propertyreferencesequential” (the field where the agent sticks the sequential number, is not in “”, or as a string.

When the number is not put in quotes, it then does not show up in the counter view, hence it giving the following documents the same number.

I have noticed that if I go into one of these “bad documents”, put it into edit mode and then save it, the quotes appear and the document then appears in the sequential view.

Therefore, a way round it would be for the agent to put the document into edit mode before it saves it, or put it into edit mode at the beginning. I cannot see the lotus script command for doing this.

Perhaps this is an issue as I am running this on 6.5 and the original code is from 6.??? Bug perhaps???

Can you help me get round this please.

Agent code attached:

Sub Initialize

 'Auto allocate Key Numbers to new Properties



On Error Goto HandleError



Dim session As New NotesSession

Dim db As NotesDatabase

Set db=session.currentDatabase



Dim viewUallocated As NotesView

Set viewUallocated=db.getView("luKeyUnAllocated")

Call viewUallocated.refresh()



'use the view so that numbers are allocated in order



Dim doc As NotesDocument

Set doc=viewUallocated.GetFirstDocument

If doc Is Nothing Then Exit Sub



Dim docNext As NotesDocument



Dim c As Double



Dim view As NotesView

Set view=db.getview("luKeyCounter")



Dim docFirst As NotesDocument

Set docFirst=view.GetFirstDocument



'Get the top entry value (or 1)

If docFirst Is Nothing Then

	c=1

Else

	c=(docFirst.getItemValue("PropertyReferenceSequential")(0)) + 1

End If 



Do Until doc Is Nothing

	

	Set docNext=viewUallocated.getNextDocument(doc)

	

	Call doc.replaceItemValue("PropertyReferenceSequential", c)

	

	Dim d As String 

	d=doc.getitemvalue("PropClientAgentReference")(0) +"/" + Cstr(c)

	Call doc.ReplaceItemValue("PropLHUKTotalReference",d)

	

	Call doc.save(True,False)

	

	If docNext Is Nothing Then Exit Do

	c=c+1

	Set doc=docNext

	

Loop



Exit Sub

HandleError:

Print Error()

Exit Sub

End Sub

Subject: Agent Help Please!

Matt,

If you are getting your field “propertyreferencesequential” not as a string, change the line

Call doc.replaceItemValue(“PropertyReferenceSequential”, c)

to Call doc.replaceItemValue(“PropertyReferenceSequential”, Cstr(c))

although, you will need this to be a number, otheerwise when you get to 100, it will appear after the entry for 10

Doing sequential numbering, you should always use numbers

HTH

Mike

Subject: RE: Agent Help Please!

Mike,

I will try that.

Silly question, but how do I make it a number as you say.

Thanks very much for your quick response and help.

Matt.

Subject: RE: Agent Help Please!

Matt,

Just make sure the datatype on the field on your Form is set to Number and also in your script, use the CInt function

Call doc.replaceItemValue(“PropertyReferenceSequential”, Cint(c))

Good luck!

Mike

Subject: RE: Agent Help Please!

Thank you very much.

You and everyone on here are very kind and help learners a lot.

Cheers,

Matt.