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

copying from main to response

Hi there,

I have a form in db saved with thousands of document. This form has only 3 fields:

field1 - place
field2 - product
field3 - amount


Now I want to split these into 2 forms, a main and a response so that I am able to create many products per place and I did that.

form 1 - main form has the following field

field2

form2 - response to main has the following fields

field2
field3
where were originally in main

Now that original database, had thousands of document which I need to copy across with the above main/response split instead of all in the one document.
Is there a quick way to do this, as this is a critical database and can make no mistakes.
I need that I have to match on univeral ID to avoid duplicate or loss of data, however a more precise solution, maybe a small script to help will be appreciated.

Thank you in advance.

0
varvoura
Asked:
varvoura
  • 11
  • 5
  • 4
2 Solutions
 
cezarFCommented:
try this. your view should display all Form1 docs

      Dim ses As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim newdoc As NotesDocument
      
      Set db = ses.CurrentDatabase
      Set view = db.GetView("ViewName")      
      Set doc = view.GetFirstDocument
      
      While Not doc Is Nothing
            Set newdoc = db.CreateDocument
            newdoc.Form = "Form2"
            newdoc.Field2 = doc.Field2
            newdoc.Field3 = doc.Field3
            Call newdoc.MakeResponse(doc)
            Call newdoc.Save(True,False)
            
            'To remove redundant fields in form1
            Call doc.RemoveItem("Field2")
            Call doc.RemoveItem("Field3")
            Call doc.Save(True,False)
            
            Set doc = view.GetNextDocument(doc)
      Wend

hope this helps.
0
 
CRAKCommented:
I'd convert the database; not copy its data. Especially if you need to keep the original doc id's!

I assume your question has a typo: form 1 gets field 1?
Create a non-hierarchical view of all documents having field 2. Sort those docs on field 1 and have your LS code cycle though it. Collect all occurances of field 1 in a list or an array.
Now run down that list or array and do 3 things:
1 = create a maindocument
2 = create a document collection from the view, of all docs having that value in field 1
3 = turn the documents in that collection into a response if the new document { Call notesDocument.MakeResponse( document ) } and remove field 1 from them (+ save!)

Having the view selecting documents that have field 2 available, filters out the new main docs (otherwise you'd need to refresh the view before each time you perform step 2, and be carefull not to turn the main doc in a response.
Making the view non-hierarchical avoids the same problem caused by step 3's mutations.

Allow yourself a thorough test-run on a db copy or a (prior to the run disabled) replica. As you said: you can't afford any mistakes here!
0
 
CRAKCommented:
!!: cezarF's solution will generate new doc id's!
(Since you wrote "I need that I have to match on univeral ID to avoid duplicate or loss of data")
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.

 
cezarFCommented:
CRAK, new doc ids for new response docs. it will keep the original doc's id

varvoura, btw, don't forget to backup your db before doing the conversion. :)

0
 
CRAKCommented:
Hmmm.... seems that we both pictured the current database differently. Yours could also be an option, but IMO you still might have chosen the response to have the original doc id. And why a main doc should have only 1 response initially, still puzzles me.

varvoura, what's the desired situation?
Should every document have it's own parent (=cezarF), or do several of the current documents share values in field 1, where you would like to see multiple responses under a common parent (=CRAK)?
0
 
varvouraAuthor Commented:
OK.

At this stage I believe that each document will have only the one response doc.
I would definitely be creating multiple responses under the one doc in future.

If I use cezarF solution, will I have a problem in future created response documents.


0
 
CRAKCommented:
Depends on what you use the id's for.
If e.g. you use @GetDocField to retrieve field 1, you'd need to end up at the main doc. If it's field 3 you're after, its the response that should get the original id.
If you need both field 1 and field 3, then you'd need to decide.... and do some additional programming in those places where the id is used! My 1st guess would then be: let the response keep the original id; it's $Ref will lead you to the main doc.
0
 
varvouraAuthor Commented:
cezarF, this doesn't seem to work properly.
The fields are deleted from main but are values not populating in response docs.
0
 
varvouraAuthor Commented:
Cezarf, I created two main docs and also created the response form with the correct field. Everytime, I run your script with these two documents in "All" view, I get 64 main/responses and not values in the responses, very weird.

I am going to try CRAK's suggestion now.

Hope to hear from any of you soon
0
 
varvouraAuthor Commented:
Should every document have it's own parent (=cezarF), or do several of the current documents share values in field 1, where you would like to see multiple responses under a common parent (=CRAK)?



Yup, several of the response document share the value in field 1. For example, field 1 is a place and field 2 is a product. In this case, I want to be able to create many response product for each place.

Is this clear now?
0
 
varvouraAuthor Commented:
CezarF,

I am keen to use your solution as it is simple to work with, but can we modify it to work.

At the moment, I only have 2 main docs in db. When I ran the agent(manually) on all docs in view, I get 64 docs in that view(All view), when I flick to "place" view, I can see 32 next to each place doc, hence 64 for 2 place docs.
The next response document in the view, has product field populated, the remaining docs, are mixture of main and response, some has populated field and some don't. There must be an easy way to do this. I am currently working  on it and I'll appreciate more ideas.
CRAK, I would like your input as well, if possible

0
 
varvouraAuthor Commented:
cezarf, a bit better now.

I deleted everything from db and created 2 new main docs.
When i ran script, I can in the view that under each main doc, 2 response documents have been created. One has the values correctly and the other just a plain blank response doc, could it be the way it is looping?
0
 
varvouraAuthor Commented:
It works fine now, the problem was with the view which was suppose to display both response and main documents. As soon i disabled response docs on view that I am cycling throw, everything worked fine.

The only problem that I have noticed that I need to refresh the view manually to pick other fields on product form.

0
 
cezarFCommented:
sorry i was away.

are you referring to the All view that the program uses? is the view open when you run the program?
0
 
varvouraAuthor Commented:
Yes, because I am running this manually.
I thought maybe we should use the uiview.refresh in the script to refresh fields.
But then we'll have to map the backend view(All) to the current view before we can refresh it.

0
 
varvouraAuthor Commented:
Also, when I refresh documents in the view, i see the following error in status bar:
Document left to process 4,NotesID causing error = 800000A8
0
 
cezarFCommented:
you can do a call ws.ViewRefresh to refresh the view. as for the error, i suggest you debug the script to know which doc is causing the error. one of the doc could be corrupted.
0
 
varvouraAuthor Commented:
Thanks cezarf,

Can I sneak in one more small quesiton.

On the new form, I have the prodno field which I want to validate so that when I try to save the document with the prodno blank, I get a prompt to fill in a value. Usually this is very easy in notes, I can put formula in field validation and it would be fine. For example, I could place in prodno field validation the following:
@if(prodno = "";@failure("pls enter a product number in.....");@success;
However, as this is a notes web application, this validation formula does not work. So I tried to place the following script on "on blur" event.

prodval = document.forms[0].prodno.value
if (prodno = "")  {
    prodval= prompt("enter a value in the Product Code")
}
prodval=document.forms[0].prodno.value

Still not working, am I testing correctly?
0
 
cezarFCommented:
it seems to me that the prob is just a little copy+paste issue. :)

prodval = document.forms[0].prodno.value
if (prodval = "")  {
    prodval= prompt("enter a value in the Product Code")
    document.forms[0].prodno.value = prodval
    document.forms[0].prodno.focus()
}
0
 
varvouraAuthor Commented:
This is not working not matter what I do with it.
I've even changed it to alert instead of prompt.
What's funny is that the alter will work on the submit but when I OK the alert box, it won't let me enter a value in the field even when I set the focus to it.

PROBLEM 2

It seems that when i create document as main/responses(cezarF) script, then I decided to remove then re-add one of the fields that I created in the response field, all the data in that field is lost, which is a nightmare, because I can't recreate responses only for that one field, I'll end up with two sets of responses for the one document. Is there anyway that I can reinstate the value of the field that I delete from the response created via the script?

Thank you in advance.
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.

  • 11
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now