shuboarder
asked on
Agent/Script to update all documents in a view
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):
https://www.experts-exchange.com/questions/21613681/Agent-to-update-all-records.html
Thanks.
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):
https://www.experts-exchange.com/questions/21613681/Agent-to-update-all-records.html
Thanks.
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("SaveOp tions","1" )
Call uidoc.refresh
Call uidoc.Save
Call uidoc.close(True)
Set doc=view.getnextdocument(d oc)
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,ndo c)
Call nuidoc.refresh
Call nuidoc.save
Call nuidoc.close(True)
k=k+1
Print "Processing "&cstr(k)
Next
End Sub
%END REM
End Sub
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
Call uidoc.FieldSetText("Escape
Call uidoc.FieldSetText("SaveOp
Call uidoc.refresh
Call uidoc.Save
Call uidoc.close(True)
Set doc=view.getnextdocument(d
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,ndo
Call nuidoc.refresh
Call nuidoc.save
Call nuidoc.close(True)
k=k+1
Print "Processing "&cstr(k)
Next
End Sub
%END REM
End Sub
ASKER
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.....
I had tried this before posting....
I get the error message:
@commands are not allowed with this UI type blah blah blah.....
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
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
ASKER
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
The error points to the following lines:
k=0
For j = 1 To ndoccol.count
ASKER
mbonaci - same error.... "Please select none as runtime target..."
Any ideas?
Any ideas?
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
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
ASKER
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....
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....
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
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
ASKER
mbonaci... I get no create - action - action
I get create agent option, but not action.
I get create agent option, but not action.
shuboarder,
did you opened the view in designer?
Marko
did you opened the view in designer?
Marko
ASKER
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.
Same bizarre message.... "Do I want to delete 352 documents from the view"
when I click the button to run the action.
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
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
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
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
ASKER
Ok... I no longer get the error, but it doesn't refresh the formulas on the document
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");
AgentB: Type @Commands Allowed.
@command([EditDocument];"1
@Command([FileSave]);
@Command([FileCloseWindow]
AgentA (or in action button) Selected Documents
@COmmand([ToolsRunMacro];"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Steve
are you still looking for help?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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([ToolsRefreshSele ctedDocs]) is the correct command to use that will do the job, in a manual action button by itself.
@Command([ToolsRefreshAllD ocs]); << 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.
If this is not to be a scheduled agent, then I agree with Steve, @Command([ToolsRefreshSele
@Command([ToolsRefreshAllD
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.
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.
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
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
ASKER
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.
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.
No problem, thanks for the points.
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.
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.
ASKER
Ok, thanks for clearing that up for me marilyng!
to refresh formulas of selected documents use:
@Command( [ViewRefreshFields] )
Hope this helps,
Marko