Solved

Author Fields and Agents

Posted on 2003-12-11
11
496 Views
Last Modified: 2013-12-18
I am currently writing an agent which I want to place on my Quickplace server.

The agent updates the values which are held in the reader and author field.  The code for the agent is below.

The problem I am having is that when the user first submits the document the only name in the author field the the users.  When the agent runs on the document it does not update the document.  

Is this because of the author field or am I missing something?  The agent has been signed by the server.

Is there anything I have missed?

-------------------------------------------

Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim groupmembers As Variant
Dim rfield As NotesItem
Dim afield As NotesItem
Dim collection As NotesDocumentCollection
Dim dt As New NotesDateTime("")
      
Set db = s.CurrentDatabase      
'Search for document with the workflow stage h_Submitted and h_New
Set collection = db.Search("@Contains(h_workflowStage;'h_Submitted':'h_New')",dt,0)      
Set doc = collection.GetFirstDocument      
      
'Process Documents
While Not(doc Is Nothing)            
      workflow = doc.h_workflowStage(0)       
      If workflow = "h_Submitted" Then
            If Not doc.HasItem ( "UpdatedDLAUsers" ) Then
                  Call SetGroupMembers(db,doc,"DLA_Admin")
            End If
      Elseif workflow = "h_New" or workflow = "" Then
            If Not doc.HasItem ( "UpdatedClientUsers" ) Then
                  Call SetGroupMembers(db,doc,"Client_Agent")
            End If
      End If
      Set doc = collection.GetNextDocument(doc)
Wend
End Sub

Sub SetGroupMembers(db As NotesDatabase, doc As NotesDocument,param As String)
      
Dim dbpath As String
Dim groupview As NotesView
Dim groupdoc As NotesDocument
Dim groupMembers() As String
Dim updateditem As NotesItem
Redim Preserve groupmembers (0)
groupmembers (0) = ""
strMembersDBFilename = "Contacts1.nsf"
dbpath=Strleft(db.filepath,"Main.nsf",5)
      
'Gets the members of the appropriate group
Dim membersdb As New NotesDatabase ( db.Server, dbpath + strMembersDBFilename)
Set groupview = membersdb.GetView("h_Groups")
Set groupdoc = groupview.getfirstdocument
Do While Not groupdoc Is Nothing
      If groupdoc.h_Name(0) =param Then
            group = groupdoc.GetItemValue ( "h_Members" )
            i=0
            Forall x In group                        
                  Redim Preserve groupMembers ( 0 To i )
                  IsinArray = Arraygetindex (groupMembers,x,5)
                  If Isnull(IsInArray) Then
                        groupMembers (i) = x
                        i = i + 1
                  End If
            End Forall
      End If
            
      'Updates Next Stage User i.e. Authoriser
      If param="DLA_Admin" Then
            If doc.HasItem ( "h_SetNextStageUser" ) Then
                  Set rfield = doc.GetFirstItem( "h_SetNextStageUser" )
                  currentUsers = doc.GetItemValue( "h_SetNextStageUser" )
                  Forall m In groupMembers
                        IsinArray = Arraygetindex (currentUsers,m,5)
                        If Isnull(IsInArray) Then
                        Call rfield.AppendToTextList (groupMembers)
                        End If
                  End Forall
            Else
            Set rfield = New NotesItem ( doc, "h_SetNextStageUser", groupMembers )
            End If
      End If
            
      'Updates Reader field
      If doc.HasItem ( "h_Readers" ) Then
            Set rfield = doc.GetFirstItem ( "h_Readers" )
            currentUsers = doc.GetItemValue( "h_Readers" )
            Forall m In groupMembers
                  IsinArray = Arraygetindex (currentUsers,m,5)
                  If Isnull(IsInArray) Then
                        Call rfield.AppendToTextList (m)
                  End If
            End Forall
      Else
            Set rfield = New NotesItem ( doc, "h_Readers", groupMembers )
      End If
      
      'Updates Author field
      If doc.HasItem ( "h_Authors" ) Then
            Set rfield = doc.GetFirstItem ( "h_Authors" )
            currentUsers = doc.GetItemValue( "h_Authors" )
            Forall m In groupMembers
                  IsinArray = Arraygetindex (currentUsers,m,5)
                  If Isnull(IsInArray) Then
                        Call rfield.AppendToTextList (m)
                  End If
            End Forall
      Else
            Set rfield = New NotesItem ( doc, "h_Authors", groupMembers )
      End If
      Set groupdoc=groupview.getNextdocument(groupdoc)
Loop

'Saves Document
Call doc.Save (True,True)
End Sub
0
Comment
Question by:fayeb
11 Comments
 
LVL 31

Accepted Solution

by:
qwaletee earned 200 total points
ID: 9922385
I really don't want to wade through fifty lines of code, and then try to debug what part os wrong.  Can  make a sugestion that will make this easier to deal with?

First, create a test form instead of your current form.  Then, create a test agent to work with that test form.  Make teh agent very small, only testing the ability to update the author field (not even the reader field).

Once we get that working, it will probably be obvious how to fix the longer agent that is associated with the real form.

OK?
0
 
LVL 24

Assisted Solution

by:HemanthaKumar
HemanthaKumar earned 200 total points
ID: 9922428
Is this agent a scheduled one ?

If this is scheduled one.. and agent signer is server then you have to include a role (assigned to server in ACL) or server name in the author field. What you can do is create another Author field and set Admin role as default. Assign this admin role to the server and admin group.

Since the author of the doc is user, server doesn't have authority to edit the document. You can see error about security in the notes log when the agent runs.

Include server name/role to the document authors.

~Hemanth
0
 
LVL 9

Assisted Solution

by:Arunkumar
Arunkumar earned 50 total points
ID: 9922640
Always have a role assigned to the Db which is super Role to access all documents.  Make this role available for All administrators and all servers in the domain.

Make sure that this role goes into a separate field Author / Reader ALWAYS.

Now, if you run your agent by server id or any adminsitrator want to do STUFF they have access to all the documents in the Database.  Its always a good practice cause you wont lose any document permanently due to the presence of reader fields.

Good Luck!
Arun.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9923315
Uh, guys, remember, this is Quickplace.  You normly set up agents as text files that you upload to an agent screen in Quickplace, and there is no agent signing authority to worry about, since Qickplace takes care of it.
0
 
LVL 15

Assisted Solution

by:Bozzie4
Bozzie4 earned 50 total points
ID: 9940347
Do you have these fields on your form : UpdatedDLAUsers ?

Because then your check will make sure the document in not updated  
(If Not doc.HasItem ( "UpdatedDLAUsers" ) Then ...)

Remove those lines (well, comment them out) and try again.

Also, add some debugging : use print lines if you have this agent scheduled (on new/modified documents, I suppose).  This will print information to the server log.

And last: if you run this agent when clicking a button, you won't see the changes in the front-end until you reload the ui....

cheers,

Tom
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 31

Expert Comment

by:qwaletee
ID: 9940351
qwaletee,

Once more,

> Uh, guys, remember, this is Quickplace.  You normly set up agents as text files that you
> upload to an agent screen in Quickplace, and there is no agent signing authority to worry
> about, since Qickplace takes care of it.


- qwaletee
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9942318
fayeb, to make things more clearer log the agent activities using print statements or using noteslog object.. Whichever is convenient !

BTW, When & how is this agent run  ?
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9942433
Coming back to Qwaletees remark

> Uh, guys, remember, this is Quickplace.  You normly set up agents as text files that you
> upload to an agent screen in Quickplace, and there is no agent signing authority to worry
> about, since Qickplace takes care of it.


The agent which has been submitted by the user (access rights determined at the run time) is run by server using the agent signer (the user who submitted the agent) access on the server.

So effectively the problem is still with agent signing.. so there should be a admin role which should also have author access to the document. If the user who submitted the document only has the access then you are never going to be successful in running the agent on that document. This is true for scheduled agents.

If the user who submit the document invoke the agent then his user credentials are used.

Ultimately the answer to this question lies on how the agent is invoked ?



0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9954753
Hemanth,

QuickPlace runs agents under the authority of the place owner.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9954966
See http://www-1.ibm.com/support/docview.wss?uid=swg21090191 and http://www-1.ibm.com/support/docview.wss?uid=swg27002693

And I'm wrong.  SCHEDULED agents run with the submitter's authority, and form agents run, I think, with the submitter's authority, but neither requires signing.
0
 

Author Comment

by:fayeb
ID: 9963289
I still haven't completely solved this one.  

I have found a work around by placing the agent directly into the database design and signing it with the server ID, this now works.

It does seem that the agent is run as the person who places the placebot however even when I did this with someone who had manager access it did not work as it should do.

Thanks for all of you comments.

I will split the points between you all as you all have helped point me a some direction!

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now