Link to home
Start Free TrialLog in
Avatar of jforget1
jforget1

asked on

Carrying data from view to new record.

Am trying to convert some code I have used in the past which captured some fields from a record when saved and opened a new record and dropped in that data. I want to do a similar thing here, but now it will be the user selects a record from a view and then clicks a New Record button and the fields in the code will be carried over to a new record of the same type. This is in an effort to save on data entry time when all the data will normally be the same. I have each field as editable with the field name as the default value. The user may need to override some of the data which is why they are editable. Here is what I have so far, but not sure how to link it to the record in the view.

Joe

Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace          
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc, newdoc As NotesDocument
      Dim linkdoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Dim Item As NotesItem
      Dim View As NotesView
      Set uidoc = workspace.CurrentDocument
      Set db = session.CurrentDatabase
      Set doc= uidoc.Document
      Set newdoc = db.CreateDocument
      Set View = Current.View
      
      newdoc.office_num = doc.office_num(0)
      newdoc.agency = doc.agency(0)
      newdoc.city = doc.city(0)
      newdoc.state = doc.state(0)
      newdoc.contact = doc.contact(0)
      newdoc.Phone = doc.Phone(0)
      newdoc.Form = "OTS Office Contact Log"
      Call uidoc.Save
      Call uidoc.close
      
      workspace.EditDocument True, newdoc
End Sub
SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jforget1
jforget1

ASKER

Dropped in your add, but now I get an error on the open of the database. Not a member: UNPROCESSEDDOCUMENTS

I added your code as follows.

Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace          
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim uidoc As NotesUIDocument
      Dim doc, newdoc As NotesDocument
      Dim linkdoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Dim Item As NotesItem
      Dim View As NotesView
      Set uidoc = workspace.CurrentDocument
      Set db = session.CurrentDatabase
      Set doc= uidoc.Document
      Set newdoc = db.CreateDocument
      Set View = Current.View
      
      If session.UnprocessedDocuments.Count!=1 Then
            Messagebox "Please select 1 document"
            Exit Sub
      End If
      Dim viewdoc As NotesDocument
      Set viewdoc= session.UnprocessedDocuments.GetFirstDocument
      newdoc.office_num = doc.office_num(0)
      newdoc.agency = doc.agency(0)
      newdoc.city = doc.city(0)
      newdoc.state = doc.state(0)
      newdoc.contact = doc.contact(0)
      newdoc.Phone = doc.Phone(0)
      newdoc.Form = "OTS Office Contact Log"
      Call uidoc.Save
      Call uidoc.close
      
      workspace.EditDocument True, newdoc
End Sub
it';s db.unprocesseddocuments,

Points for sjef :)

Partha
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi bro, me deeply ashamed... :$
Both ways have their place :-)

Steve
Now the error opening the DB is

Type Suffix does not match data type: COUNT

I swapped in DB for Session in the 2 spots above.
use <> for not equal != is formula language and ! is a typing character for variables :-)
OK i changed the not equal sign, when I run through debugger I get an object variable not set error on Set doc=uidoc.Document. I tried remarking that line out and reran the code. Now it is a Variant does not contain an object error on the line Set View = Current.View
Just check whether the code is in click event , or some other event also

partha
Aaaaaaargh!! It's Friday, once again...

There is no doc yet, so you did right to comment that line out. Do the same with the line with Current.View .
Current.View should be (can't remember and haven't got notes open: workspace.currentview or maybe session.currentview

You don't need to the set doc= bit because you aren't using it.

Then further down you are getting viewdoc but using doc to set the newdoc fields.  They should all be viewdoc instead I guess.

Good point, not using currentview either is it :-)
Ok I am getting farther through the code, but I am now getting a  Variant does not contain an object error on the  newdoc.office_num = doc.office_num(0) line, I think because I have remmed out the doc line above it.
Change them to viewdoc instead of doc.
OK I think it is almost perfect, I have to rem out the Call doc save and close statements at the end of the code. One last thing I wonder if can be added. Right now when I do this, it does open the new doc and carry over the data, but it stays on the view and the new doc is one tab over. I wonder if code can be added to have it move over to the new record at the end of this process so the user is looking at the new record.  I know there will be people who keep clicking the button because they do not see that the new record has been created.
The focus... Hard to handle within Notes. Do you use frames in your application?

I'd also like to suggest to try dragon-it's solution, i.e. with the inherited field values. When you give each field in the document a default value of the field from the document in the view, it is supposed to work very easily. No coding whatsoever. It's just a @Command([Compose]; "yourform") and all fields to be copied must have a default value. Only once the values from the document in the view will be used, when setting the default values. Even fields with the same name should have a formula, so if the field XXX appears in both forms, it must have a default formula XXX.
I just tried the inherit values method, but that does not seem  to work pulling the values when selected in a view. It will do it if I am in a record, what I think I may do is put another button at the doc level and advise the users to open the record first and then click new. I think this will work.

Thanks for the help.

Joe
Thanks to all for the help, learned a couple ways to make this work.
No problem, thanks for the points. It should work fine from the view level BTW?

Steve