?
Solved

Agent/Script to update all documents in a view

Posted on 2006-05-31
28
Medium Priority
?
5,290 Views
Last Modified: 2013-12-18
Hi all,

I've asked this question before, but Sjef talked me out of it ;)

What I would like to do is run an agent/script to update all records in a view.

By update I mean: open document for editing and save and close.
I need this to update formulas for every individual document
I also need this to loop until all documents in the view are updated.

I have looked around on EE, but have not found anything that works correctly.
BTW, this is for Notes client 6.5

The last time I asked this I did not get a real solution just a script that seemed to loop forever (until I did ctrl + break):

http://www.experts-exchange.com/Applications/Email/Lotus_Notes_Domino/Q_21613681.html

Thanks.
0
Comment
Question by:shuboarder
  • 9
  • 9
  • 4
  • +2
28 Comments
 
LVL 22

Expert Comment

by:mbonaci
ID: 16798648
Hi shuboarder,
to refresh formulas of selected documents use:
    @Command( [ViewRefreshFields] )

Hope this helps,
Marko
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 16798692
This may help:
Sub Initialize
      Dim ss As New notessession
      Dim db As notesdatabase
      Dim view As notesview
      Dim dc As notesdocumentcollection
      Dim doc As notesdocument
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      
      Set db=ss.currentdatabase
      Set view=db.getview("Phone List\By Name")
      Set dc = db.unprocesseddocuments 'this collects the flagged documents
      
      Set doc=view.getfirstdocument
      'For j = 1 To dc.count
            'Set doc = dc.getnthdocument(j)
      '      Set uidoc = ws.editdocument(True,doc)
      '      Call uidoc.refresh
      '      Call uidoc.Save
      'Call uidoc.close
      '      Set doc=dc.getnextdocument(doc)
      'Next
      While Not doc Is Nothing
            Set uidoc=ws.editdocument(True,doc)
            Call uidoc.FieldSetText("Escape","OK")
            Call uidoc.FieldSetText("SaveOptions","1")
            Call uidoc.refresh
            Call uidoc.Save
            Call uidoc.close(True)
            Set doc=view.getnextdocument(doc)
      Wend
%REM
Description: I have a very large database that computes job payroll amounts via a 'Rate' field. The problem is, this field is computed so the workers can't give themselves a raise. My company recently had a retro-active pay increase that affected well over 200 documents. I made an Agent with a simple action that modified the 'Rate' field and ran it on all the selected documents, but I needed a way to refresh each individual document so the rate change computed through to the invoice total. I wasn't about to manually open, refresh and save each document, so I wrote a simple LotusScript to do the dirty work. It creates a notes document collection of all the documents selected in the database and runs the script on those docs.

Create an action in the database where you need to refresh documents. Label it 'Script Refresh Docs' or something like that. Set it to act on 'Selected documents.' Select Run 'LotusScript' and place the following code in the Declarations and Initialize sections of the Agent.

This script is very flexible, as there isn't any database or document-specific information in the script. Simply paste the Agent into the database, open it in the client, select the documents that you want to refresh in a View and run the Agent from the Actions menu. Enjoy!

 
 
Code: Declarations
Dim nuiw As notesuiworkspace
Dim nuidb As notesuidatabase
Dim ndb As notesdatabase
Dim ndoccol As notesdocumentcollection
Dim ndoc As notesdocument
Dim nuidoc As notesuidocument

Initialize
Sub Initialize
Set nuiw = New notesuiworkspace
Set nuidb = nuiw.currentdatabase
Set ndb = nuidb.database
Set ndoccol = ndb.unprocesseddocuments 'this collects the flagged documents
k=0
For j = 1 To ndoccol.count
Set ndoc = ndoccol.getnthdocument(j)
Set nuidoc = nuiw.editdocument(True,ndoc)

Call nuidoc.refresh
Call nuidoc.save
Call nuidoc.close(True)
k=k+1
Print "Processing "&cstr(k)
Next

End Sub
%END REM
End Sub
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16798738
I don't think this is possible is it?

I had tried this before posting....

I get the error message:

@commands are not allowed with this UI type blah blah blah.....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:mbonaci
ID: 16798761
shuboarder,
just create the view action and put the formula I posted in it.

If you always want to refresh all docs in the view use something like this:

    @Command( [EditSelectAll] );
    @Command( [ViewRefreshFields] );
    @Command( [EditDeselectAll] )

Hope this helps,
Marko
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16798793
Madheeswar.... that looks more like expected. However, I am getting "document command is not available" error.

The error points to the following lines:

k=0
For j = 1 To ndoccol.count
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16798817
mbonaci - same error.... "Please select none as runtime target..."

Any ideas?
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16798852
shuboarder,
Open your view where you want the action.
Create new action and paste the code in it.

Or if you insist on using agent select none as Target in Agent properties (you can't specify two different selections - because you use selectAll in your formula).


Hope this helps,
Marko
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16798924
This is bizarre....

Put this in an agent:

@Command( [EditSelectAll] );
    @Command( [ViewRefreshFields] );
    @Command( [EditDeselectAll] )

I have set the agent target to None... now when I run it, it asks me if I want to delete 352 documents from the database....
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16799060
shuboarder,

Open your view where you want the action.
Create new action (From toolbar: Create - Action - Action) and paste the code in it (without changing anything except action name).


Hope this helps,
Marko
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16799128
mbonaci... I get no create - action - action
I get create agent option, but not action.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16799215
shuboarder,
did you opened the view in designer?

Marko
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16799275
ok.... I hadn't opened it in designer....

Same bizarre message.... "Do I want to delete 352 documents from the view"
when I click the button to run the action.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16799332
shuboarder,
do you maybe have some docs marked for deletion?

Are those 352 docs all docs of the view (Use "ctrl + a" to select all docs in the Notes Client and you'll see the number of docs at the status bar)?


Marko
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16799361
shuboarder,
restart the computer (or all Lotus windows).

Try to copy the database (using Database - New Copy...) and you'll get an error message if it's corrupted.

Hope this helps,
Marko
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16799647
Ok... I no longer get the error, but it doesn't refresh the formulas on the document
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16799735
Hmm, thinking out loud without a Notes client,  how about:

AgentB:  Type @Commands Allowed.

@command([EditDocument];"1");
@Command([FileSave]);
@Command([FileCloseWindow]);

AgentA (or in action button) Selected Documents

@COmmand([ToolsRunMacro];"AgentB");

0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 600 total points
ID: 16803330
Hang on a minute.  What's wrong with an action or run-once agent with the following @commands:

@Command([ToolsRefreshAllDocs]);
@Command([ToolsRefreshSelectedDocs])

Steve
0
 
LVL 18

Assisted Solution

by:marilyng
marilyng earned 300 total points
ID: 16804433
Steve, I don't think either can be scheduled, same is true for the @Commands, they're available until you try and schedule them, then the "none" is not available, and the agent won't run with the @Command Fomula.

So that nixes:
@Command([ToolsRefreshAllDocs]);
@Command([ToolsRefreshSelectedDocs])
@Command([ViewRefreshFields]);
@Command( [EditSelectAll] );
@Command( [ViewRefreshFields] );
@Command( [EditDeselectAll] )


Might as well add my two/four/eight cents.

Since there is no collection method to refresh or a view method to refresh, the only thing left is the boring step through the view, as sjef Originally suggested.

Sub Initialize
      Dim Session As New NotesSession
      Dim db As NotesDatabase
      Set db = session.currentdatabase
      Dim doc As NotesDocument
      Dim view As NotesView
      Set view = db.GetView("refreshme")
      If view Is Nothing Then Exit Sub            
      Set doc =view.getfirstdocument
      While Not doc Is Nothing
            With doc
                  .ComputeWithForm False, False
                  .save True, False, True
                  Set doc = view.getNextDocument(doc)
            End With
      Wend
End Sub


0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16804879
I can't actually see anywhere where it asks for it to be scheduled though it is hinted at in the previous Q so fair enough, it does also say Notes client not server.

Steve
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 16805515
are you still looking for help?
0
 
LVL 22

Assisted Solution

by:mbonaci
mbonaci earned 100 total points
ID: 16805568
shuboarder,
sorry, my mistake, this will work for sure, I tested it (put it in view action, not in scheduled agent):

    @Command( [EditSelectAll] );
    @Command([ToolsRefreshSelectedDocs])
    @Command( [EditDeselectAll] )

or simply this:

    @Command([ToolsRefreshAllDocs]);

Hope this is it,
Marko
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16805632
Ok, let's review.  Marko's last suggestion is the adaptation of Steve's suggestion of which command to use.  

If this is not to be a scheduled agent, then I agree with Steve, @Command([ToolsRefreshSelectedDocs]) is the correct command to use that will do the job, in a manual action button by itself.

@Command([ToolsRefreshAllDocs]); << again suggested by Steve will refresh ALL documents in the database, and will run in a manual agent or action button.

Neither @Command can be put into a scheduled agent, because the "none" selection is unavailable.  It can be put into a manual action, as long as you can select "none".  

If you want it to be in a scheduled agent, then I think you have to use script.


0
 
LVL 18

Expert Comment

by:marilyng
ID: 16805652
Oops, forgot to say, maddy's script is the first in... I didn't see it, maddy, sorry!!  Mine is a shorter version of the same basic idea.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 16805705
oops, sorry,
I skipped the dragon's post where he mentions ToolsRefreshAllDocs
That's the command I was searching for, but have used ViewRefreshFields earlier by mistake.


Marko
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16840933
Marilyng - thanks for clearing things up...

I was after a scheduled agent, but from Sjef's original code this seems to take much longer than running it manually through an action, I don't know why...?

I will make do with running it manually for now. - Thanks Steve.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16846028
No problem, thanks for the points.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16847793
shuboarder,

ComputewithForm  is known for consuming processing power, and so we usually avoid using it with large number of documents in a scheduled agents.   It's usually faster to just push the computed values into the fields rather than use computewithform.


The manual agent is using the resources on your computer, which is why it runs faster.
0
 
LVL 21

Author Comment

by:shuboarder
ID: 16850228
Ok, thanks for clearing that up for me marilyng!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

809 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