SwitchToId and Sign methods

Here we go. I have an agent written in LS called in the Notes client. In it, I use to SWITCHTOID method of the Notesregistration class to switch to another id. When I look at the value of the NotesSession’s properties while I debug, I can clearly see I’ve switched to the new id.

Then, I call the SIGN method of the Notesdatabase. From what I understand, this method is supposed to sign with the CURRENT userid which is, in my case, the new one I’ve just switched to.

For some strange and incomprehensible reason, the SIGN method signs all design elements with the PREVIOUS (!!) userid, behaving as if I had never switched! Even stranger, if the database I try to sign resides on a server, it works !! If it resides on a local hard disk (where I do most of my work), it fails!

I just don’t know what to think. ANY help is appreciated.

Subject: SwitchToId and Sign methods

Hi,

Here is an extract for the Help entry for the SwitchToID method:

Usage

This method works only on a client.

Which probably explains why it is doing what it is doing, but doesn’t solve your problem. I guess that you are trying to get this to work in a scheduled agent. The quick solution would be to sign the agent with the ID that you want to do the signing. Another thing you may want to investigate is the “Run on behalf of” property of the agent (Not something I’ve used. It claims to change the From for sent emails, but not sure if it will affect signing).

Hope this helps a bit.

Cheers

Alan

Subject: RE: SwitchToId and Sign methods

Response Posted in Case someone else stumbles into this trap…

The problem occurs when you initialize the “target” database for signing prior to the switchidto…

So (Pseudo Code)…

Setup Session

Open the DB you want to sign…

Switch ID’s

Sign DB

(DB Get’s signed with the Original Sessions Environment (First UserID)

Change it to:

Setup Session

Switch ID’s

Open the DB you want to sign…

Sign DB

DB Get’s signed with the new ID’s information… When you see it that way it makes perfect sense why… but had me scratching my head for a few minutes…

Anyway here is a working example…

Dim S As New NotesSession

Dim signdb As NotesDatabase

Dim userid As String

Dim signid As String

Dim notespath As String

Dim result

Dim reg As New NotesRegistration

signid=“C:\notes\data\signature.id”

signpass=“XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”

signfile=“C:\notes\data\test.ntf”

'Save the current useridinfo to switch back to afterwards…

notespath = S.GetEnvironmentString (“Directory”,True)

userid = S.GetEnvironmentString (“KeyFilename”,True)

'Switch to signid to do signing

Call reg.SwitchToID(signid,signpass)

Set SignDB=New NotesDatabase(“”,“”)

If Not SignDB.Open(“”, SignFile ) Then

Print "TEMPLATE NOT FOUND!!"

Exit Sub

Else

Call SignDB.Sign(32767,False,,False)

End If

'Switch Back…

result = Evaluate(“@Contains(”“”+userid+“”“;”“:”“)”)

If Result(0) = 1 Then

Call reg.SwitchToID (userid)

Else

Call reg.SwitchToID (notespath+"\"+userid)

End If