Working with Agent Properties: $flag

We are in the process of writing an agent that will will clean-up a bunch of database’s on our server that use the same template, but database managers made changes that we want to reverse.

Besides Cleaning up the help documents, and folders we are also trying to clean-up agents.

For the agent part we are doing two things.

#1 Check all agents, and if enabled, disable them. Easy enough and working.

The 2nd part that we’d like to do is check the “prohibit design refresh” flag and disable it if it is enabled.

Agent part:

Forall agent In rdb.Agents

If agent.Trigger= TRIGGER_MANUAL Then

	Goto nextagent

End If

If agent.Isenabled Then

agent.Isenabled = False

End If

The next part is what I’ve tried, we used this to check folders, but doesn’t work for agents since there is no “view” to capture agents from to get the Items propertie:

Set item = agent.GetFirstItem( “$Flags” )

If Not item Is Nothing Then

pos = Instr(item.Text,“P”) 'see if Preserve is listed

If pos <> 0 Then 'we need to unprotect agents

tmpString$ = Left$(item.Text, pos-1) & Right$(item.Text, Len(item.Text)-pos)

Call agent.ReplaceItemValue(“$Flags”, tmpString$) 'set flags without “Preserve”

End If

End If

nextagent:

End Forall

Any help you can give me would be greatly appreciated!

Thanks,

Shane Meisner

Subject: Working with Agent Properties: $flag

So what exactly are you looking for? A way to get a handle on the agent design note?

Have a look at NotesNoteCollection.

Subject: RE: Working with Agent Properties: $flag

Thanks… I’ve been looking at that.

It looks like in order to go that route I’d need to export the data to a file, change the flag and then bring it back.

Having not done that before it maybe beyond the time scope of what they are giving me and so may have to finish all but that part and return to it when I find time.

Basically I just want to check each agent and see if the Prohibit switch is enabled. If so, disable it. With Folders and views it is a simple matter of checking the $flag and removing the “P” if it exists.

I was hoping it ws just a simple with Agnets.

Thanks,

Shane Meisner

Subject: RE: Working with Agent Properties: $flag

No need to do that. As I said, all you need is a handle to the agent’s design note, so you can manipulate it just like any other document.

The core of your code could look somewhat like this:

Dim nnc As NotesNoteCollection

Set nnc = db.CreateNoteCollection(False)

nnc.SelectAgents = True

Call nnc.BuildCollection()



If (nnc.Count > 0) Then

	Dim nid As String

	nid = nnc.GetFirstNoteId()

	Dim designNote As NotesDocument

	Dim posP As Integer

	Dim curFlags As String

	Dim newFlags As String

	While (Not nid = "")

		Set designNote = db.GetDocumentByID(nid)

		curFlags = designNote.GetItemValue("$Flags")(0)

		posP = Instr(curFlags, "P")

		If (posP > 0) Then

			newFlags = Join(Split(curFlags, "P"))

			Call designNote.ReplaceItemValue("$Flags", newFlags)

			Call designNote.Save(False, True)

		End If

		nid = nnc.GetNextNoteId(nid)

	Wend

End If

Subject: RE: Working with Agent Properties: $flag

Very nice!!

Thanks… Worked like a charm!