Hello,
I would like to take a value from a field(“ROI_Total_Cost_Savings” in the code below) in one database and move that value to a like field in an EXISITING form (“frmCase1”) in another database. We have a unique document identifier field that could link the correct cases called “Case#” but we don’t know how to work with the LotusScript code that’s attached below. We have this code placed in the form of the original db under Postsave.
Any help you can provide will be great!
-Matthew
Sub Postsave(Source As Notesuidocument)
Dim Session As New notesSession
Dim ws As New NotesUIWorkspace
Dim CMdb As Notesdatabase
Dim uidoc As NotesUIdocument
Dim CMws As New NotesUIworkspace
Dim CMuidoc As notesUIdocument
Set uidoc=ws.CurrentDocument
Call uidoc.Save
ROI_Total_Cost_Savings=uidoc.FieldGetText("ROI_Total_Cost_Savings")
Call uidoc.Save
Call uidoc.close
Set CMuidoc = CMws.ComposeDocument( "MD-Dev1/CFMD" ,"Medical\CM.nsf" , "frmCase1")
If ROI_Total_Cost_Savings>0 Then
Call CMuidoc.FieldSetText("LastPositiveROI",ROI_Total_Cost_Savings)
End If
Call CMuidoc.Save
Call CMuidoc.close
End Sub
Subject: Interesting LotusScript Question
no comments added and cleaned up a little more, I noticed Session and CMdb was not being used and so I removed those as well. Then I just moved a couple lines around to look better. Let me know if this works for you. I also removed converting the text to integer, you can just do this inline within the logical test greater than 0. You should still Dim it though like I do below. Good day.
Sub Postsave(Source As Notesuidocument)
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIdocument
Dim CMws As New NotesUIworkspace
Dim CMuidoc As notesUIdocument
Dim ROI_Total_Cost_Savings As String
Set uidoc=ws.CurrentDocument
ROI_Total_Cost_Savings=uidoc.FieldGetText("ROI_Total_Cost_Savings")
Set CMuidoc = CMws.ComposeDocument( "MD-Dev1/CFMD" ,"Medical\CM.nsf" , "frmCase1")
If Cint(ROI_Total_Cost_Savings)>0 Then
Call CMuidoc.FieldSetText("LastPositiveROI",ROI_Total_Cost_Savings)
End If
Call uidoc.Close
Call CMuidoc.Save
Call CMuidoc.close
End Sub
Subject: RE: Interesting LotusScript Question
Great, Cint helps very much with our eventual formulas.
One more thing, Larry, what’s the coding in Script wherein I can link up two databases (CM.nsf and ROI.nsf) using a unique field so that the value in “ROI_Total_Cost_Savings” (from ROI.nsf) moves into the correct document in CM.nsf?
Thanks again,
Matthew
Subject: RE: Interesting LotusScript Question
I am not really sure how to do this. I think what you are asking is for CM.nsf/document/ROI_Total_Cost_Savings to just link to field on a document in the Roi.nsf file. You would probably need to code this for when the document is opened to look somewhere else for the data and then just fill it in. But within the same database you can have different forms that have fields that link to the same data.
Subject: RE: Interesting LotusScript Question
Yeah took me a while to get it right because I am at work and had other things going on at the same time. At first I was a little confused as to what you were actually trying to do and how to begin playing with it but for once I wanted to try to help someone being I always asking for help. I just opened a memo note and did my testing from there which also meant I had to use different fields for testing.
I agree with the other comments though. Most of the time I use NotesSession, NotesDatabase, NotesDocumentCollection, NotesDocument, etc. but being you had something already started I just tried to work with what you had.
Subject: Interesting LotusScript Question
this is all fine and dandy but why dont you all of this in the backend? that way you wont see the document opening and closing in front of u.
Dim doc As notesdocument
Dim uidoc As notesuidocument
Dim ws As NotesUIWorkspace
Dim db As NotesDatabase
Dim targetdb as Notesdatabase
Dim session As New NotesSession
Dim NewDoc As NotesDocument
Set db = session.currentdatabase
Set ws = New NotesUIWorkspace
Set uidoc = ws.Currentdocument
Set doc = uidoc.document
Set targetdb=New notesdatabase("name_of_server","name_of_db.nsf")
'create the new document in the other db
Set NewDoc = New NotesDocument(db)
NewDoc.Form = "Name_of_Form"
NewDoc.Field1 = doc.Field1(0)
NewDoc.Field2 = doc.Field2(0)
Call newdoc.Save(True, False)
Print “Successfully created new document.”
HTH
ST
Subject: RE: Interesting LotusScript Question
Our form in CM.nsf creates the document in ROI.nsf. After the user enters a value in ROI.nsf we want to be able to transport that value back to the original document in CM.nsf using a unique identifier we have in both of our forms in both databases.Matthew
Subject: RE: Interesting LotusScript Question
That is irrelevant, really – LotusScript can create documents directly in the database without opening them to the user interface. In other words, there’s no reason to use ComposeDocument from the workspace, since you can use CreateDocument from the NotesDatabase. Set all of the field values you need, including Form.
Subject: RE: Interesting LotusScript Question
Stan, We’re not looking to create a new document – we want this data to go back into an existing document. Luckily we have a unique identifier in both of our forms in both of the databases.
Is there anyway to do this?
Thanks!
Subject: RE: Interesting LotusScript Question
of course, but from the example that you wrote you were actually creating a new doc (in case you didnt notice).To update an existing DOCUMENT (not form - a form is just a design object) you have to call a sorted/categorized view. getdocumentbyey (using that unique indetifier) and the set the fields in that document.
here is an example:
Set view = db.GetView ("Name_of_View")
key = Cstr(doc.Unique_Identifier_Field(0))
Forall c In view.Columns
If ( c.IsSorted And c.IsCategory ) Then
Set column = c
Exit Forall
End If
End Forall
Set newdoc = view.GetDocumentByKey( query )
Do While Not ( newdoc Is Nothing)
If ( newdoc.ColumnValues( column.Position - 1 ) = _
query) Then
newdoc.field1 = doc.Whatever_field(0)
newdoc.Field2 = “whatever” Call newdoc.Save (True, False, True)
Else
Exit Do
End If
Set newdoc = view.GetNextDocument( newdoc )
Loop
Subject: RE: Interesting LotusScript Question
… and use the CreateDocument method to create a new document if GetDocumentByKey returns Nothing.
Subject: RE: Interesting LotusScript Question
Good idea!
btw, matthew, all of these examples are available in the designer help. it’s an invaluable tool.
ST
Subject: RE: Interesting LotusScript Question
That’s fantastic, Thank you very much.
As a marginal user of LotusScript this forum is of great help. And I apologize for throwing everyone off by having having coding for creating a new doc in my original code.
Matthew
Subject: Interesting LotusScript Question
try this:
Sub Postsave(Source As Notesuidocument)
Dim Session As New notesSession
Dim ws As New NotesUIWorkspace
Dim CMdb As Notesdatabase
Dim uidoc As NotesUIdocument
Dim CMws As New NotesUIworkspace
Dim CMuidoc As notesUIdocument
Set uidoc=ws.CurrentDocument
Dim ROI_Total_Cost_Savings As Integer 'why not just make an integer because you logicall test against this below
'Call uidoc.Save 'why save we haven't done anything to this document
ROI_Total_Cost_Savings=Cint(uidoc.FieldGetText("ROI_Total_Cost_Savings")) 'use Cint() to convert text data to integer
'Call uidoc.Save 'why save we have not done anything to this document
'Call uidoc.close 'this is not a problem but I prefer to close below being this is small
Set CMuidoc = CMws.ComposeDocument( "MD-Dev1/CFMD" ,"Medical\CM.nsf" , "frmCase1")
If ROI_Total_Cost_Savings>0 Then
Call CMuidoc.FieldSetText("LastPositiveROI",ROI_Total_Cost_Savings)
End If
Call uidoc.Close
Call CMuidoc.Save
Call CMuidoc.close
End Sub