• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Agent to update users in a Users View

I have a view that list all my users.  The users names are created form the UserForm.  There a about 10 fields on the form.  The fields are populated from a lookup address book when the user is created.  The problem is that unless I go in to the username and update the profile, it is outdated with information.  So I asked a question about creating a agent that will do it nightly for me.  Here is what I wrote.

SELECT Form = "UserForm";
FIELD ShortName := @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "ShortName");
FIELD UFirstName := @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "FirstName");
FIELD ULastName := @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "LastName");
FIELD UEmail := @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "MailAddress");
FIELD Department := @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "Department");
FIELD UPhone := @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "OfficePhoneNumber");
FIELD UOffice:= @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "OfficeNumber");
FIELD UBuilding := @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "BLDG");
FIELD UManager := @DbLookup("":"NoCache";"domino1/Company":"names.nsf"; "($Users)"; UserName; "Manager");
@True

runs daily
All new and modified documents
runtime security 2

The is problem is - If I set it to run for the action bar and I select one document in the view - it will update as it should.  But when I leave it to run daily all the fields are filled in with:

ERROR: You are not authorized to perform that operation.

Maybe I need to do this is LS?  The only documents I want updated are the UserForm docs and I only have one view that displays all the users View =Users.

But I need this working very soon!

0
Jaziar
Asked:
Jaziar
  • 9
  • 9
1 Solution
 
madheeswarCommented:
Check if the user sigened this agent has proper access to NAB and also to run Schedule agents.
0
 
JaziarAuthor Commented:
The user that signed the agent is manager of the database.  
0
 
Sjef BosmanGroupware ConsultantCommented:
R5?? From the Designer Help db:
"Agents running on R5 or earlier servers can only access target databases stored on the same server as the source database."
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
JaziarAuthor Commented:
R6

I can select the document and run the agent fine, it is only when I schedule it, I have these problems
0
 
Sjef BosmanGroupware ConsultantCommented:
Other server also R6?
0
 
JaziarAuthor Commented:
Yes - both are R6
0
 
Sjef BosmanGroupware ConsultantCommented:
Check the log.nsf database, what it says when the agent runs. Probably you don't have enough provoleges, as Maddy suggests.
0
 
JaziarAuthor Commented:
As a developer, I do not get access to the log.nsf file.  Only the System admins gets to see the server logs.  
0
 
Sjef BosmanGroupware ConsultantCommented:
There is no way you can develop proper software without access to the log database. If you don't have access yourself, either get it through your manager, or ask the Admins to provide you with the information you need. What you are looking for are error messages of the Agent Manager from the time you ran the agent.
0
 
JaziarAuthor Commented:
trust me when I say I have tried to get the correct access.  Our I/T is outsourced and they do not like to give out access to any of the servers.  So I do the best I can with what I have.  I can always run the agent from the menu and it works, but I would have to remember to run it daily and that is too mush overhead on my part.  What if we changed it to a LS ?  Do you think that would help?  I would really prefer it in a LS to be honest.

Jaz
0
 
Sjef BosmanGroupware ConsultantCommented:
Then write it in LS! Must be a piece of cake for you, after all the LS you have done, and it seems more efficient than all the NoCache's you use... ;)
0
 
Sjef BosmanGroupware ConsultantCommented:
But couldn't you have asked your boss to try to force the admins to assist you? I think we already discussed this point back in the past, just forget it...
0
 
JaziarAuthor Commented:
As Always Bosman you are correct, what would I do if I did not have you keeping me on track?

Sub Initialize
      Dim Session As New NotesSession
      Dim userName$
      Set SourceDb = Session.CurrentDatabase
      Dim SourceDoc As NotesDocument
      Dim SourceView As NotesView
      Set SourceView = SourceDB.GetView( "User Info\By Name" )
      
      Dim TargetDb As New NotesDatabase( "domino1/Company","names.nsf" )
      Dim TargetView As NotesView
      Set TargetView = TargetDb.GetView( "($Users)" )
      Dim TargetDoc As NotesDocument
      
      Set SourceDoc = SourceView.GetFirstDocument
      While Not(SourceDoc Is Nothing)
            userName$ = SourceDoc.UserName(0)
            Set TargetDoc = TargetView.GetDocumentByKey(userName$ )
            If Not (TargetDoc Is Nothing) Then
                  SourceDoc.UFirstName = Targetdoc.FirstName
                  SourceDoc.ULastName = Targetdoc.LastName
                  SourceDoc.UEmail = Targetdoc.MailAddress
                  SourceDoc.ShortName = Targetdoc.ShortName
                  SourceDoc.Department = Targetdoc.Department
                  SourceDoc.UPhone = Targetdoc.OfficePhoneNumber
                  SourceDoc.UOffice = Targetdoc.OfficeNumber
                  SourceDoc.UBuilding = Targetdoc.BLDG
                  SourceDoc.UManager = Targetdoc.Manager
                  flag% = SourceDoc.save(True, True)
            End If
            Set SourceDoc = SourceView.GetNextDocument(SourceDoc )
      Wend
      Call SourceView.refresh
      
End Sub

Took 5 minutes to write, waiting to see if it will run scheduled
0
 
Sjef BosmanGroupware ConsultantCommented:
Brilliant! One question though, or more, one addition: use some condition to decide whether or not to update your local document. It makes no sense to update it unless the User-document has been changed since the last update. So, my suggestion would be:
- add a field UserLastUpdated, that contains the Modified date of the User document in names.nsf
- modify your agent to use this field, like this (with some small modifications):

Sub Initialize
     Dim Session As New NotesSession
     Dim userName As String
     Dim SourceDb As NotesDatabase
     Set SourceDb = Session.CurrentDatabase
     Dim SourceDoc As NotesDocument
     Dim SourceView As NotesView
     Set SourceView = SourceDB.GetView( "User Info\By Name" )
     
     Dim TargetDb As New NotesDatabase( "domino1/Company","names.nsf" )
     Dim TargetView As NotesView
     Set TargetView = TargetDb.GetView( "($Users)" )
     Dim TargetDoc As NotesDocument
     Dim ismodified As Integer
     Dim modtime As Variant

     Set SourceDoc = SourceView.GetFirstDocument
     Do Until SourceDoc Is Nothing
          userName = SourceDoc.UserName(0)
          Set TargetDoc = TargetView.GetDocumentByKey(userName$ )
          If Not (TargetDoc Is Nothing) Then
               ismodified= True
               If SourceDoc.HasItem("UserLastUpdated") Then
                    modtime= SourceDoc.UserLastUpdated(0)
                    If IsDate(modtime) Then
                        If CDat(modtime)>=TargetDoc.LastModified Then
                             modified= False
                        End If
                    End If
               End If
               If ismodified Then
                   SourceDoc.UFirstName = Targetdoc.FirstName
                   SourceDoc.ULastName = Targetdoc.LastName
                   SourceDoc.UEmail = Targetdoc.MailAddress
                   SourceDoc.ShortName = Targetdoc.ShortName
                   SourceDoc.Department = Targetdoc.Department
                   SourceDoc.UPhone = Targetdoc.OfficePhoneNumber
                   SourceDoc.UOffice = Targetdoc.OfficeNumber
                   SourceDoc.UBuilding = Targetdoc.BLDG
                   SourceDoc.UManager = Targetdoc.Manager
                   SourceDoc.UserLastUpdated= TargetDoc.LastModified
                   Call SourceDoc.save(True, True)
               End If
          End If
          Set SourceDoc = SourceView.GetNextDocument(SourceDoc )
     Loop
     Call SourceView.refresh
     
End Sub

0
 
JaziarAuthor Commented:
Very Nice Indeed - Good catch
0
 
JaziarAuthor Commented:
added your stuff and added some script that will shoot me a email everytime the agent runs.  Once again when I click the run button it runs great, but when I schedule it, it will not run at all.  I am manager of the database and the agent is running on behalf of myself.  I have signed the agent.  I have no clue why this will not run.
0
 
Sjef BosmanGroupware ConsultantCommented:
Just checking: did you also add the line
    SourceDoc.UserLastUpdated= TargetDoc.LastModified

The ONLY way to get an answer is to ask the admins. I thought that these people had to do what the owner tell them to?? Just call them, they are human too (usually)...
0
 
JaziarAuthor Commented:
I have sent a request through my manager asking for the needed access
0
 
Sjef BosmanGroupware ConsultantCommented:
Yessss! Let's hope they want to cooperate...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now