Readers Field and Agent

Hi, I have a field on a form that I have set as a Readers field, I also have an agent that stamps the field with a Notes group following a lookup. However, after the agent has stamped the field it no longer acts as a reader field, instead the field type is simply SUMMARY. How can I stamp this field using the agent (@SetField formula language) and still use it as a readers field?

Any help greatly appreciated

Regards

Mike

Subject: Readers Field and Agent

If you don’t mind using Lotusscript, see this thread:

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/9d2ed9b74658f45b85256f38006f7d75?OpenDocument

Hope that helps.

Subject: RE: Readers Field and Agent

Many thanks for your reply, I have to admit that I haven’t used LotusScript before so wouldn’t be sure where to put it. What I need to do is set the value of a readers field I have created on the form to the value of another field whilst retaining it’s readers field property. I don’t suppose you know how this could be done do you?

Thank you

Regards

Mike

Subject: RE: Readers Field and Agent

Is this part of the design of the form? Can you just set the Readers field as computed and as a formula, use the name of that other field? Or at least incorporate the lookup into the Readers field. That’s the only way I know of to use @functions to set a Readers field. Only if they’re part of the Readers field formula.

Or are you referring to a one time update? Is that why you were using an agent?

Using LS in an agent to set the Readers field should be relatively easy. But give more details on how this lookup is being performed and how the agent is being called and maybe I or someone else can give you a hand.

Subject: RE: Readers Field and Agent

The agent runs before new mail is delivered and does a lookup within the same database, it then uses @Setfield to set the mailinggroup field in the form with the lookup result. I wish to have this same value entered into another field (a readers type field called ReadAccess) but if I use @Setfield it seems to change the field flag to ‘SUMMARY’ rather than ‘SUMMARY READ ACCESS NAMES’ then it doesn’t act as a readers field. Obviously I need the ReadAccess field setting before the user has access to it…

many thanks

Subject: RE: Readers Field and Agent

Looks like I’m mistaken. According to the FAQ on Reader/Author fields, (see here ==> http://www-10.lotus.com/ldd/46dom.nsf/11a0b6a64ffb3d8d85256a4c004f1bbd/e0359d10a2307d1885256c61000707b7?OpenDocument)

you can set a readers field through a simple FIELD assignment. I don’t know if that would work in your scenario of a “before new mail arrives” agent but give it a shot.

The alternative might have to be LotusScript in your agent.

Hope that helps.

Subject: RE: Readers Field and Agent

Again, thank you for your help. I have just tried setting the value of the reader field from within a scheduled agent, the only code in it was:

FIELD ReadAccess:=MailingGroup

this has set the ReadAccess field to the value of the MailingGroup field but still the field type flag is SUMMARY…

Sadly I am a novice with LotusScript, is there any chance you could let me know how to do this please? It would be greatly appreciated as I cannot figure out another way to do this. The computewithform command would appear to be the answer but I would not know how to use this within an agent…

Regards

Subject: RE: Readers Field and Agent

Like I said before, the LS code to update a Readers field is not involved. But there are a few things I need to point out.

A database can only have one “before new mail arrives” agent so if you want to go this route, we’ll have to replace the whole agent with LS. If the only other thing you’re doing in this agent to doing the lookup, and placing the value in the MailingGroup field, it’s not a problem. But if your doing other things in the agent with @formulas, those will also have to be translated into LS.

We could just leave your “before new mail arrives” agent alone and set up a separate “After new mail arrives” agent with this LS code to update the Readers field. Since I don’t know what your requirements were when setting this application up, you may need this done before the document is actually placed into the database. But this approach seems kind of wasteful, having multiple agents running each time a new document arrives just to perform one function.

To start with, post the code in your current agent. Or you can just email it to me if you want (email address in my profile).

Subject: RE: Readers Field and Agent

The code in my ‘before new mail’ agent involves 2 lookups (within the same database) and then uses the two returned values to set 2 field values within the form, the code is:

MailingGroup:=@DbLookup(“”:“NoCache”;“”;“LookupView”;SendTo;“EmailGroupLU”;[FailSilent]);

GroupDescription:=@DbLookup(“”:“NoCache”;“”;“LookupView”;SendTo;“DescriptionLU”;[FailSilent]);

@SetField(“MailingGroup”;MailingGroup);

@SetField(“GroupDescription”;GroupDescription);

@PostedCommand([ViewRefreshFields]);

SELECT @All

Would another option be to call a simple ‘refresh’ agent from the agent above and include the simple LS in here rather than convert the above to LS?

Many thanks

Subject: RE: Readers Field and Agent

I’ve never tried calling another agent from a “before new mail arrives” agent. But I think there are @commands/functions that will not work in this kind of agent. It wouldn’t hurt to try that if my code fails though.

For what it’s worth, here’s my quick and dirty approximation of your agent:

Sub Initialize

Dim ses As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim docLookup As NotesDocument

Dim itemReader As NotesItem



On Error Goto ErrRtn



Set db = ses.CurrentDatabase

Set view = db.GetView("LookupView")		'get handle to lookup view

Set doc = ses.DocumentContext				'get handle to incoming document

Set docLookup = view.GetDocumentByKey(doc.SendTo(0), True)			'get handle to lookup document based on SendTo

If docLookup Is Nothing Then

	Print "No document found in LookupView with key '" & doc.SendTo(0)

	Exit Sub

Else

	doc.GroupDescription = docLookup.DescriptionLU

	Set item = New NotesItem(doc, "MailingGroup", docLookup.EmailGroupLU, READERS)

	Call doc.Save(True, False, True)

End If	



Exit Sub

ErrRtn:

Print "Error " & Cstr(Err) & " - " & Error & " occurred at line " & Cstr(Erl)

End Sub

Disable your current agent and create a new one with the code above. There’s minimal error checking. Of course, I haven’t tested it. Let me know how it turns out.

Hope that helps.

Subject: RE: Readers Field and Agent

Thank you so much for your help, your code works well for what I need and it has also helped me to understand LS a bit more. I now need to try and add to your code to also add an authors field so that I as administrator can see all the documents.

Many thanks

Regards

Mike

Subject: RE: Readers Field and Agent

Glad I could be of assistance.

You can also check the Designer help for the NotesItem LS class. There are examples of how to set up Authors fields and also how to add multiple values to the fields using arrays. Good luck!

Subject: RE: Readers Field and Agent

Yes, I found the author part in the Help just after I’d done my last post and thats working now too.

Thanks again

Mike