I have two forms and two views in the same application. Form A is displayed in View A and Form B is displayed in View B.When I update information in Form A I would like a computed field in Form B to update so I can use the updated information in Form A.
If I update the information in Form A and save the document, and then run an agent on View B the information is updated.
Here is the script for the AGENT.
Sub Initialize
Dim w As New notesuiworkspace
Dim col As notesdocumentcollection
Dim midoc As notesdocument
Dim s As New notessession
Dim db As notesdatabase
Set db=s.currentDatabase
Set col=db.unprocessedDocuments
Set midoc=col.getFirstDocument
Do While Not midoc Is Nothing
midoc.a = 30
Call midoc.ComputeWithForm(True,False)
Call midoc.save(True,False)
Set midoc=col.getNextDocument(midoc)
Loop
End Sub
This works well except I have to trigger this from View B. I am not a great at scripting.
Thanks for your time.
Subject: Update Computed Field in Different Form Document
You need some key in both docA and docB to be able to find docB and a view listing the ‘B’ docs with col 1 sorted on that key.Just set the two constants below and run this in postsave or wherever…
Sub Postsave(Source As Notesuidocument)
Const VIEW="???????????"
Const KEYFIELD="?????????"
Dim ss As New notessession
Dim db As notesdatabase
Dim doc As notesdocument
Dim vw As notesview
Dim vwdoc As notesdocument
Dim key$
On Error Goto lerr
Set db=ss.currentdatabase
Set doc=source.document
'if docA doesn’t store a key for referencing B in a field then compute key$ here.
key$=doc.getitemvalue(KEYFIELD)(0)
Set vw=db.getview(VIEW)
If vw Is Nothing Then Error 4712,"View " + VIEW+ " not found"
Set vwdoc=vw.getdocumentbykey ( key$, True)
If vwdoc Is Nothing Then
Error 4711, "Can't find document for " + key$
Else
vwdoc.a = 30
Call vwdoc.ComputeWithForm(True,False)
Call vwdoc.save(True,False)
End If
Exit Sub
lerr:
Msgbox "Error: " & Error$ & " Line: " & Erl
Exit Sub
End Sub
Subject: RE: Update Computed Field in Different Form Document
Haydn,Thanks for your response, I may have not explained the situation clearly. The script you have supplied is very usefull, however maybe not this time. DocA uses the Documents in ViewB for drop down selection boxes. DocB are active or inactive. Once they are inactive they should not show up in the selection box. DocB becomes inactive after choosen by any DocA to fill a field.If I open ViewB and run an agent and then go back to DocA, DocB does not show up in the selection box. Will the script that you supplied execute this?
Thanks for your time.
Subject: RE: Update Computed Field in Different Form Document
The problem is that your selection list is not up to date with the view contents, then.
You can make the selection list be up to date as soon as your form A is refreshed by doing the following:
Make sure your keyword formula uses “NoCache” option in the @DbColumn call.
Tick the form option to refresh choices on document refresh.
The problem is that when you exit the view and return to form A, you’re not automatically refreshing the form. Not sure offhand whether the onfocus form event will work in the Notes client – you could try it. Otherwise, you might write your agent in such a way that it could be run from form A, perhaps with an action button, and in that same action formula, refresh the form.
Another consideration – might look at the architecture of your application. It looks like you’re trying to create a one-to-one relationship between two different types of documents (e.g. each “form A” document “claims” one form B document). It’s sometimes easier to do this by merging the two different types into one document.
Alternately, to reduce the chance of conflicts from two users working on the same “form B” key at once, you could add a view action to view B that simultaneously creates the form A, fills in the field that refers to form B, and changes the B document so that it’s no longer in the view.
Note, however, that if the A document is not saved, you’d want to put the B document back like it was. This is one more reason to use a single form for both, perhaps using the document locking feature to prevent simultaneous editing.
Subject: RE: Update Computed Field in Different Form Document
Thanks for your response and time. You have provided some food for thought. The structure of my application is Form A is a transaction form. View B and Form B are a list of all ticket numbers that are available for the Transaction in Form A.There is one document for each ticket available in Form A and View B. Form B has a computed field with a DBLookup into view A to see which tickets were selected by Form A. If I open View B and the Agent executes then the view is accurate as to which tickets are sold. I require a method of executing the agent in View B when I close Form A.Thanks for your time.