Solved

Copying documents using LotusScript agent

Posted on 2002-06-06
17
1,477 Views
Last Modified: 2013-12-18
Hi experts,

How can I copy documents using a LotusScript agent ?

The agent should work as follows:

- Prompts the user for a selectionbox with 4 values in it
- Looks for the chosen value in a field on the documents which are present in a view **
- copy's the documents that matches the criteria to the same database and put on those new documents a new field with a value (doesn't matter what the value is)

** The source documents have a multivalue field. The value that the user entered (using the prompt) can be found in this field

Greetings,

Bob
0
Comment
Question by:oosterbaan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
17 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7059374
Check this script out, ( I used Multvals as the field for search)

     Dim s As New NotesSession
     Dim db As NotesDatabase
     Dim doc, note As NotesDocument
     Dim col As NotesDocumentCollection
     Dim ws As New NotesUIWorkspace
     Dim uidoc As NotesUIDocument
     
     Set uidoc = ws.CurrentDocument
     Set note = uidoc.DOcument
     Set db = s.CurrentDatabase
     Forall v In note.multvals
          searchPara = searchPara & {@IsMember( "} & v & {"; MultVals) & }
     End Forall
     searchStr = Left( searchPara, Len(searchPara) - 2)
     Set col = db.Search( searchStr, Nothing, 0)
     Print col.Count
     Set doc = col.GetFirstDocument
     
     While Not doc Is Nothing          
          If Ubound(note.multvals) = Ubound(doc.MultVals) Then
               Set newdoc = doc.CopyToDatabase(db)
               newDoc.newValue = "Blah!Blah!"
               Call newDoc.Save(True,False)
          End If
          Set doc = col.GetNextDocument(doc)
     Wend

~Hemanth
0
 
LVL 1

Author Comment

by:oosterbaan
ID: 7059448
Hi HemanthaKumar,

I have a few questions about your code:

How is the value you are looking for assigned ?
Is this agent running only from the selected view ?
When I run your agent I get a error message: "Object variable not set"

Greetings,

Bob
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7059935
I assume this script is run from the currently opened document, which has multvals field with available options, when you select few of them and hit this button script, the search begins with taking the field value from the document and copying takes place.

So to test this script, put it in a button and create a field called multvals in the form and assign few dummy options and save few docs and then finally use the same form to search for the saved options.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:oosterbaan
ID: 7060340
Hi Hemanthakumar,

OK, I understand, but what I really want is a button in a view that will call "this" agent. This agent then searches for documents within this view which matches the criteria (in you're case the FIELD multvals on the documents) and copies those documents to the database (and add the new field).
If this is to complex I'm also helped out if this agent only copies all the documents from this view and adds a new field to the copied documents.

Greetings,

Bob
0
 
LVL 1

Author Comment

by:oosterbaan
ID: 7061366
Since I'm am not a complete idiot (-: I have figured out some code to copy the documents from a view that works fine for me. The only thing that would be great is to implement the search in this code that will not copy all the docs but a selection of the docs in this view. The user will get a InputBox with 4 values and must select 1 of them. Then this code will look for the documents that have this value in the multivalue field...

This is the code sofar:

Sub Initialize
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim view As NotesView
     Dim DocTitle As Variant
     Dim doc As NotesDocument
     Set db = session.CurrentDatabase
     Set view = db.GetView("Alle Protocollen")
     Set doc = view.GetFirstDocument
     While Not (doc Is Nothing)
          DocTitle = doc.ProtocolNaam          
          Set newdoc = doc.CopyToDatabase(db)
          newDoc.CopyStatus = "1"
          Call newDoc.Save(True,False)
          Set doc = view.GetNextDocument(doc)
     Wend
     Msgbox("Documents are copied")
End Sub
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7062599
Create an agent to run on selected documents with this script in it. I have commented the lines and read it carefully

Sub Initialize
     
     Dim s As New NotesSession
     Dim db As NotesDatabase
     Dim doc, note As NotesDocument
     Dim col As NotesDocumentCollection
     Dim ws As New NotesUIWorkspace
     Dim choices(3) As String
     Set db = s.CurrentDatabase
     ' Replace this choices with original one
     choices(0) = "a"
     choices(1) = "b"
     choices(2) = "c"
     choices(3) = "g"
     choice = ws.Prompt( Prompt_OKCANCELLISTMULT, "TITLE", "PROMPT", choices(0), choices )
     If Not Isempty(choice) Then
          Set col = db.UnprocessedDocuments
          Set note = col.GetFirstDocument
          While Not note Is Nothing
               matchcount = -1      ' match array index to 0
               If Ubound(note.MultVals) = Ubound(choice) Then    ' Does doc and choice match
                    Forall v In note.MultVals
                         Forall c In choice
                              If c = v Then
                                   matchcount = matchcount + 1
                              End If
                         End Forall
                    End Forall
                    If matchcount = Ubound(choice) Then
                         Gosub CopyDoc
                    End If
               End If          
               Set note = col.GetNextDocument(note)
          Wend
          Print matchcount
     End If
     Exit Sub
CopyDoc:
     Set newdoc = note.CopyToDatabase(db)
     newDoc.CopyStatus = "1"
     Call newDoc.Save(True,False)
     Return
End Sub
0
 
LVL 1

Author Comment

by:oosterbaan
ID: 7064776
I'm almost there HemanthaKumar,

The code is working fine when the value you're looking for is the first in the list of the MultVal field. For example: I give the user these values as choice: MAJOR, HGP, BOROS and COMB. When the MultVal field contains the value MAJOR,HGP and the user selects HGP, the document is not selected to copy. When the user would have selected MAJOR, the document will be copied...

Another small comment and maybe easy to solve:

During the selection, the user is able to select multiple values in the InputBox. Is it possible to force the InputBox the accept only one value ?

Greetings,

Bob
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7068123

Use Prompt_OKCANCELLIST instead of Prompt_OKCANCELLISTMULT in the above code for single selection.

Give me your completed code and will test



0
 
LVL 1

Author Comment

by:oosterbaan
ID: 7069875
OK....

The second answer is easy... I will replace the OKCANCELLISTMULT by OKCANCELLIST

Maybe I can send you the complete .NSF ???

Greetings,

Bob
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7071471
Hemanth1@bigfoot.com is my id
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7076062
Bob,

Recieved your mail and it works for me.

Let me explain what the agent will do, it will not do partial matches.

It will look if the Multval field matches exactly to the selected list. In your case you said atleast one value should match to copy, Is that what you were looking for ???
0
 
LVL 1

Author Comment

by:oosterbaan
ID: 7076479
Hi HemanthaKumar,

My experience with the code is, that it works when the "InspectieSoort" field contains more then one value, for example "MAJOR,COMB" and I'm looking for COMB (the second value of the list), the document is NOT selected for copying. When in the same case, I would have selected MAJOR (the first value on the list), the document will be selected for copying...

The document should be selected when the value selected using the InputBox function in the example is MAJOR or COMB...so I thougt using a @Contains function that will check the "InspectieSoort" field that will search for the value in the "InspectieSoort" list.

Greetings,

Bob
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7076544
Ok then replace this statement

If matchcount = Ubound(choice) Then

with

If matchcount >= 0 Then
0
 
LVL 1

Author Comment

by:oosterbaan
ID: 7077652
Hi HemanthaKumar,

Great....the selection works fine now...

Only one little detail and I'm ready to go (-:

You have said to change the prompt_OKCANCELLISTMULT to prompt_OKCANCELLIST so that the user can select only one value. When I do this, and the agent is started, I get a Type Mismatch Error.
When I start the LotusScript debugger, I can see that the error message is generated in the line Forall C in Choice (line 21)..Can you explain that ?

Thanks for sofar...

Greetings,

Bob
0
 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 150 total points
ID: 7078599
That small change requires a new code and here it is..

Sub Initialize
     Dim s As New NotesSession
     Dim db As NotesDatabase
     Dim doc, note As NotesDocument
     Dim col As NotesDocumentCollection
     Dim ws As New NotesUIWorkspace
     Dim choices(3) As String
     Set db = s.CurrentDatabase
    ' Replace this choices with original one
     choices(0) = "MAJOR"
     choices(1) = "COMB"
     choices(2) = "HGP"
     choices(3) = "BOROS"
     choice = ws.Prompt( Prompt_OKCANCELLIST, "TITLE", "PROMPT", choices(0), choices )
     If Not Trim(choice) = "" Then
          Set col = db.UnprocessedDocuments
          Set note = col.GetFirstDocument
          While Not note Is Nothing
               matchcount = -1      ' match array index to 0
               Forall v In note.InspectieSoort
                    If choice = v Then
                         matchcount = matchcount + 1
                    End If
               End Forall
               If matchcount >= 0 Then
                    Gosub CopyDoc
               End If
               Set note = col.GetNextDocument(note)
          Wend
          Print matchcount
     End If
     Exit Sub
CopyDoc:
     Set newdoc = note.CopyToDatabase(db)
     newDoc.CopyStatus = "1"
     Call newDoc.Save(True,False)
     Return
End Sub

0
 
LVL 1

Author Comment

by:oosterbaan
ID: 7079328
Thanks HemanthaKumar for your patience and expertise (-:

Greetings,

Bob
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7081562
You are welcome.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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 article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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