Change agent properties programmatically

Hi

Is it possible to change the “Run on Behalve of” agent property through Lotusscript?

Regards

Subject: Change agent properties programmatically

Yes. But not via the Agent / NotesAgent class, since that property is read only.

Here is some sandbox code, you can use to experiment with it…

step 1 - create a view called ($$Design)

selection formula - leave as simple search (so it returns all docs).

column1 (sort, categorize, use twistie for expand/collapse). use this formula:

f := $Flags;

c := @If(f = “CUA3” : “CUAx3”; “Subform”; f=“Y”:“Yw” : “PY”; “View”; f=“G3”; “Navigator”; @Begins(f; “34CiQ”); “Image Resource”; @Begins(f;“C34WQ”); “Page”; f=“s34Q”; “Script Library”; f=“fL3” | @Contains(f; “f”) & (@Contains(f; “3”)); “Agent”; f=“P”; “Shared Field”; f=“3FY”; “Shared Folder”; f=“3FYV”; “Private Folder”; @Contains(f; “C”); “Form”; f=“”; “Shared Field”; “”);

@IfError(c; “”)

column2 - use this formula: $Title



column3 - use this formula: @Text(@DocumentUniqueID)



column4 - use this formula: @NoteID

save the view

step 2 - create and execute this agent, so that your view will display design notes instead of documents…

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument



Set db = session.CurrentDatabase

'–CUSTOMIZE:Change the name of the view below to customize

Set view= db.GetView("($$Design)")

'–You now have a handle on the design element of the view.

Set doc = db.GetDocumentByUNID(view.UniversalID)

'–CUSTOMIZE: The code on the line below changes the $FormulaClass field.

'–See chart above for other values.

Call doc.ReplaceItemValue("$FormulaClass", "1548")

doc.Save True, True

and step 3 - you create an agent to manipulate the on behalf off.

Here is some sandbox code to experiment with… and enjoy.

**warning, disclaimer. do not try this at home, etc. **

Dim s As New notessession

Dim db As notesdatabase



Dim agent As NotesDocument

Dim view As notesview

Dim vec As NotesViewEntryCollection

Dim ve As notesviewentry



Set db = s.CurrentDatabase

Set view = db.GetView("($$Design)")

Set vec = view.GetAllEntriesByKey("Agent")

Set ve = vec.GetFirstEntry

Set agent = ve.Document



Dim nn As New NotesName(s.EffectiveUserName)

Msgbox agent.~$title(0)

agent.~$OnBehalfOf = nn.Canonical

Call agent.Save(False, False, False)	

' is this going to sign the design note properly?... hmm,maybe not. lets force a signing now



Dim a As NotesAgent

Set a = db.GetAgent(agent.~$title(0))

Call a.Save

Subject: RE: Change agent properties programmatically

Hi

Thank you for the posting. I tried to find this code in sandbox, but could not find it. Can you give me the url of tis sandbox webpage?

I tried what you posted, but the OnBehalfOf agent property remains empty. It looks like when I do the last save of the agent object, that field is emptied.

Regards

Subject: RE: Change agent properties programmatically

the code does work, i verified it. although you need to point to the correct agent.

the sandbox code I provided just grabs the first agent (sorted alphabetically) and modifies it. You would actually need to know how to code in LotusScript to go any further. For example, to modify to code to change a specific agent.

You could either change the key to agent~$title or loop through all agents until the $title matching the agent you want to set is found.

I also get an error about “This agent contains an illegally added ‘On behalf’ attribute. To make the agent valid please remove it.

When saving the document/agent (I definitely have a handle on the agent I want to update)

Hi,

This is possible programmatically by using NotesNoteCollection and SelectAgents property. Here’s a sample LotusScript:

Dim session As New NotesSession
Dim db As NotesDatabase
Dim nnc As NotesNoteCollection
Dim doc As NotesDocument
Dim agentName As String
Dim nid As String

On Error GoTo checkerror

Set db = session.CurrentDatabase

agentName = "TestAgent" ' Replace this with the exact name of the agent**

'Build a collection of all agents in the database

Set nnc = db.CreateNoteCollection(False)
nnc.SelectAgents = True

Call nnc.BuildCollection

'Then, loop through the collection to find the agent by name

nid = nnc.GetFirstNoteID

Do While nid <> ""

	Set doc = db.GetDocumentByID(nid)

	' Design elements store their name in the $Title field
	If InStr(doc.GetItemValue("$Title")(0), agentName) > 0 Then

		'Remove the illegal property if it exists
		If doc.HasItem("$OnBehalfOf") Then
			Call doc.RemoveItem("$OnBehalfOf")
			Call doc.Save(True, False)

			Print "Successfully removed 'On Behalf Of' for: " & agentName
		End If
		Exit Do
	End If
	nid = nnc.GetNextNoteID(nid)
Loop

checkerror:
If Erl > 0 Then

	Print "Error on line# " & Erl & " >> " & Error

End If

====================================

Regards,

TJ