Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

R5 - Concatenating docs based on a duplicate field

Status
Not open for further replies.

JoseQuiervo

Programmer
Sep 25, 2002
57
US
I have a model number field that is duplicated (no more than 2 copies of the same data). What I'd like to do, is bring the 2 docs that have the duplicate model number together as one doc in a view. Is this possible?

(ie)
ModelNumber - xyz, Field2 - 10, Field3 - 2500
ModelNumber - xyz, Field2 - 100, Field3 - 1450

What I want:
ModelNumber - xyz, Field2 - 10/100, Field3 - 2500/1450

Now, the slash is a slash not a divisor. And that doesn't necessary have to be how it looks, it's just an example. The rest I can do, I just would like to bring the 2 docs together that have the same model number.

Thanks for the help!
 
What you're doing is essentially taking two different documents based on a key, and copying some items from one doc to another.
You're going to need a view that lists docs by the key. Then you need an agent that will go through all docs in the view, get the key, find the other doc, copy the fields you want from one to the other, delete the redundant doc and save the important doc.

Would you like some example code to get you started ?

Pascal.
 
No function in Notes to do that - you'll have to code.

I would suggest developing something along these lines :

1) make a view with all docs by key ModelNumber
2) create an agent that does the following :
- for all docs in view
- find other model number doc
- copy required fields to first doc
- delete redundant doc
- save current doc

Would you like me to flesh this out in code to get you started ?

Pascal.
 
I'd appreciate that...I just need to know how to get started and I can go from there. Thanks for all your help.
 
Okay, here is a first draft :

Code:
Dim session as new notessession
dim db as notesdatabase
dim view as notesview
dim coll as notesdocumentcollection
dim doc as notesdocument
dim olddoc as notesdocument
dim refdoc as notesdocument
dim keyval as string

set db = session.currentdatabase
set view = db.getview(viewname)'insert name of key view here
set refdoc = view.getfirstdocument
do while not(refdoc is nothing)
    keyval = refdoc.keyfield(0)'insert name of key field here
    set coll = view.getalldocumentsbykey(keyval)
    if coll.count = 0 then
        'need warning message ?
    else
        set doc = coll.getfirstdocument
        'put code for copying field data here
        doc.deleteflag = "1"
        call doc.save(true,true)
        if coll.count > 1 then
            'need to decide what to do if this happens
        end if
    end if
    set olddoc = refdoc
    set refdoc = coll.getnextdocument(olddoc)
    delete olddoc
loop
This draft expects a view to exist, sorted by key value.
If there is more than two docs with the same key value, then will be some additional work to do. I don't know if that can happen in your design, so you can edit that out if it is not relevant.
There is code to write concerning the copy of field data to the reference document.
I do not know if you want to warn about refdocs without corresponding doc. If you want to automate, you can still write a line in the log about this (with the Print function).

There, I hope this helps.

Pascal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top