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!

How to Inherit value in previous response document

Status
Not open for further replies.

musafir

IS-IT--Management
Mar 11, 2003
2
MX
I have created a system for medical tracking. Main document will be a personnell particulars info and response document will show the transaction of medical activities untill peryear end. Every person entitled for RM1000 peryear for medical treatment benefit. Every time they visit the doctor the amount RM1000 (total amount field) will be deducted based on the cost of medical. The deducted amount is called amount balance in amount balance field. How to inherit value from amount balance into the new created document (in total amount field) in response document? Please help me and thank you in advance.
 
Let me guess : each new visit is recorded by creating a document from the main document, right ?
In that case, the previous AmountBalance is contained in a response document somewhere under the main doc, response which is not being used for creating the response.
You can develop the code to use a response doc to respond to a main doc. Notes specifically handles that, given that a Response form can be created from a response, but will respond to the main document. Yet, it will inherit from the response doc.
However, I do not think you should rely on the operator to choose the right response document all the time. People are human and humans make mistakes. If the mistake is that they did not choose the right customer record, well, there is no safeguard against that. But you can avoid the mistake of not choosing the right record by not inheriting that value.
Instead, have the response form use the QueryOpen event to look up the last response document and store the value in a temporary variable. The PostOpen event can then use that to fill in the AmountBalance field.
You will need a view to do the lookup, and you will almost certainly need to do the lookup in LScript.
Aside from that, this issue should not be all that difficult to solve.
I'm willing to help if need be.

Pascal.
 
I am a beginner. Can I have some sample lotus scipts on:
1) how to lookup the last response and store the value in a temporary variable,
2)Lotus Script in PostOpen to fill in the AmountBalance field.
Thank you very much
 
Before creating code for looking up a document, you need a view that presents documents in a certain way.
It is up to you to determine how the view should present the documents.
You can then write the lookup code, depending on how the view was set up.

Here, we have main documents and response documents. The two are based on two different forms.
A response doc is defined by the fact that the record created always contains a field named $Response. This field contains the UniversalID of the main document that it responds to.
So what you can do is create a view listing all main and response docs, without respecting hierarchy (it is a property of the view). This detail is generally important for purposes of sorting.
The first column of this view should contain a formula like this :

Code:
@if(form=<main form name>;@text(@documentuniqueID);$Response)

In the next column, you want the field containing the remaining amount.
Both columns must be sorted. The first can be sorted either ascending or descending. The second column must be sorted descending.

Once you have this view working, searching for the last doc is a trivial exercise in LScript. The code to do it is as follows :

Code:
dim session as new notessession
dim uiws as new notesuiworkspace
dim uidoc as notesuidocument
dim db as notesdatabase
dim view as notesview
dim coll as notesdocumentcollection
dim doc as notesdocument
dim dockey as string

set uidoc = uiws.currentdocument
set db = session.currentdatabase
dockey = uidoc.fieldgettext(&quot;$Response&quot;)
if not (dockey = &quot;&quot;) then
set view = db.getview(<view name>)
set coll = view.getalldocumentsbykey(dockey)
if coll.count > 0 then
set doc = coll.getlastdocument
call uidoc.fieldsettext(&quot;AmountBalance&quot;,doc.AmountBalance(0))
end if
end if

Now, a few remarks.
* First, this code supposes that all response docs are created from the main doc only. If that is not the case, you will have to amend the code a bit to take into account creating from the main doc and creating from a response doc.
* Second, it requires that the field $Response be created on the response form. Make it a hidden field, type text and editable. Put no formulas in the field definitions.
* Third, it supposes that the search code is put in the PostOpen event of the Response form. The reason for that is that the UIdoc is only available after the document has actually been opened. You could design something similar for the QueryOpen event, but you would have to keep the info stored somewhere until the PostOpen was available anyway.

There, that should be enough to get you started.

Good luck !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top