Lotuscript agent operating on 2 documents

Currently, this agent assigns a sequential tracking number to a document by looking in a view (DocNo) these documents are stored, finding the greatest number, and incrementing it by one.

Due to security, those documents have access control, so I need to generate a hidden document (DocNo) at the same time which will have the same tracking number but stored in a different view (DocNoHolder) without access control.

I am stumped. Can someone show me how to make this agent look at that access control free view to generate the tracking number while still assigning the tracking number to the original document?? Apparently its not as easy as I thought

Sub Initialize

Dim workspace As New notesuiworkspace

Dim session As New notessession

Dim db As notesdatabase

Dim uidoc As notesuidocument

Dim lookupdoc As notesdocument

Dim doc As notesdocument

Dim view As notesview

Set db = session.currentdatabase

Set uidoc = workspace.currentdocument

Set doc = uidoc.document



xyear = Format(Date , "yyyy")

key = xyear

Set view = db.getview("DocNo")

Set lookupdoc = view.getdocumentbykey(key)

If lookupdoc Is Nothing Then

	x = 1

	doc.number = 1

Else

	y = lookupdoc.number(0)

	x = y + 1

	doc.number = y + 1

End If

If x <= 9 Then

	DocNo = xyear & "-" & "000" & x

Elseif x > 9 And x <= 99 Then

	DocNo = xyear & "-" & "00" & x

Elseif x > 99 And x <= 999 Then

	DocNo = xyear & "-" & "0" & x

Else

	DocNo = xyear & "-" & x

End If

doc.DocNo = DocNo

Call uidoc.Refresh	

End Sub

Subject: Lotuscript agent operating on 2 documents

Run this code from within an agent. Only the agent signer need to have access to the original document. You don’t need a second document in this case.

HTH

Sai

Subject: RE: Lotuscript agent operating on 2 documents

Well, the reason why im generating that second document without access control is because when the tracking number agent runs, it will not see other documents created by other users because of access control, so it will start over at 001.

Subject: RE: Lotuscript agent operating on 2 documents

Sign the Agent with the Server id and update the readers field so that it contains the server name. The agent now can see all the documents.

HTH

Sai

Subject: RE: Lotuscript agent operating on 2 documents

I’m new to this, can you tell me how? Thanks

Subject: RE: Lotuscript agent operating on 2 documents

You may try the following:

  1. Create a role [SuperUser] in the ACL for your database.

  2. Sign the agent with your id for example.

  3. In the ACL assign the role [SuperUser] to your ACL entry.

  4. If your tracking documents contains readers field then Update the readers field for all the tracking documents so that it contains the [SuperUser] role. If the reader access is controlled by a view property security tab “All readers and above” then select this role [SuperUser].

  5. Now, since the agent is signed by your id and your id has [SuperUser] role and the [SuperUser] role is contained in readers fields or view security, the agent should be able see all the documents.

HTH

Sai

Subject: RE: Lotuscript agent operating on 2 documents

If I signed the agent correctly by clicking “Sign” on the agents view, then this method did not work

Subject: RE: Lotuscript agent operating on 2 documents

I will not be able to do that, the notes admin will not allow such things. What im trying to do im sure isnt that far fetched. I just want this agent to look at a different view.

Subject: RE: Lotuscript agent operating on 2 documents

In any case, you probably want the LotusScript to run as the current userto leverage security.

What I’d do is store a single document to track the number. There’s no need to create a seprate tracking document for each stored document.

I’d position this as a function for cleaner code.

Function getNewDocNo as Integer

. . '-Return a new document number

. . Dim sess As New NotesSession

. . Dim db As NotesDatabase

. . Dim view As NotesView

. . Dim doc As NotesDocument

. . Dim newNo as Integer

. .

. . Set db = sess.CurrentDatabase

. . Set view = db.getView(“LastNoTrackerView”)

. .

. . If view.EntryCount = 0 then

. . . . newNo = 1

. . . . Set doc = db.CreateDocument

. . . . doc.Form = “LastNoTracker”

. . else

. . . . Set doc = view.GetFirstDocument

. . . . newNo = doc.LastNo(0) + 1

. . End If

. .

. . '-Store the newest number

. . doc.LastNo = newNo

. . call doc.Save(True, True)

. .

. . '-Return the number

. . getDocNo = newNo

. .

End Function

This approach increments the last number automatically on the assumption that

the document using the number will be stored.

Advantage:

  • More likely to avoid multiple documents (from different users) being stored

with the same number

Disadvantage:

  • If multiple calls are made without the document being saved, then you may get

gaps in the numbers.

Replace this code:

Set view = db.getview(“DocNo”)

Set lookupdoc = view.getdocumentbykey(key)

If lookupdoc Is Nothing Then

x = 1

doc.number = 1

Else

y = lookupdoc.number(0)

x = y + 1

doc.number = y + 1

End If

If x <= 9 Then

DocNo = xyear & “-” & “000” & x

Elseif x > 9 And x <= 99 Then

DocNo = xyear & “-” & “00” & x

Elseif x > 99 And x <= 999 Then

DocNo = xyear & “-” & “0” & x

Else

DocNo = xyear & “-” & x

End If

with

DocNo = xyear & “-” & Right(“000” + CStr(getNewDocNo),4)

Note also that you’d have to create the initial tracking document to “prime” the correct value as well as the lookup view.

Subject: RE: Lotuscript agent operating on 2 documents

If you want to be sure there will be NO GAPS in the numbering then you should put this code on the PostSave event of the form. And do not forget to call doc.Save once again.