In a view I have created a checkbox action button. The action button shows/hides the checkbox based on the formula I have set:
#If( AAAR = True; #True; #False )
I declared the variable AAAR under the view's declaration section like this:
Dim AAAR As Boolean
Now this flag is set in the OnSelect event so that whenever users clicks/selects a document from the view, this event triggers:
Sub Onselect(Source As Notesuiview)
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim uiview As NotesUIView
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set uiview = ws.CurrentView
Set doc = db.GetDocumentByID(uiview.CaretNoteID)
If doc.GetItemValue("AllotmentApprovalReq")(0) = "Yes" Then
AAAR = True
Else
AAAR = False
End If
End Sub
Now the problem is that, i want the checkbox menu should change its status (checkbox / no checkbox) based on this value AAAR. I have to do 'something' in
the OnSelect event but i don't know how to access and set the checkbox menu from there. Please help.
Wow, this is a total mess: First of all: #Formulas variables and LotusScript- Variables have nothing to do with each other. In #Formula whenever you write a variable name it is always one of the following two:
An item with that name in the document that is currently in focus (an open document or the document under the cursor in a view). Beware: Actions are NOT automatically recalulated when you select another document, you need to enable the action bar properties of the view to update on focus change
A variable from earlier in the same formula
If your example is right, then the formula in your action button would simply be:
#If( AllotmentApprovalReq = "Yes"; #True; #False )
No need of any code in Onselect at all...
But again: You need to set the view action bar to recalculate on every focus change.
Related
Before this I ask this question and #Torsten Link suggest that I filter document to prevent user from select different document. Basically I have view, and in this view I have list of document sort by Faulty Status which I set as PFStatus. So I have three status which is Obsolete, Spoilt, and Not Found. So I want to filter so that user choose either these three status only and cannot be mixed up.
So I try to filter using below code but nothing happened.
Set doc = dc.GetFirstDocument()
If (doc.PFStatus(0) = "Obsolete" And doc.PFStatus(0) = "Spoilt" And doc.PFStatus(0) = "Not Found") Then
Messagebox"Please choose either one Write Off selection!"
Exit Sub
Elseif (doc.PFStatus(0) = "Obsolete" And doc.PFStatus(0) = "Spoilt") Then
Msgbox"Please choose only one Write Off selection!"
Exit Sub
Elseif (doc.PFStatus(0) = "Obsolete" And doc.PFStatus(0) = "Not Found") Then
Msgbox"Please choose only one Write Off selection!"
Exit Sub
Elseif (doc.PFStatus(0) = "Spoilt" And doc.PFStatus(0) = "Not Found") Then
Msgbox"Please choose only one Write Off selection!"
Exit Sub
Else
'Some code...
End If
So how can I filter selection of documents? Did I put the code in wrong way? Any help I really appreciate. Thank you. :)
Update question
Below are my view name "WriteOff". And I have a button to create new batch. So I want to try prevent user from create a batch with mixed up Faulty Status.
I created a sample on how to do this
Best is not to put your code in the button, but to create an agent to put your code in. Like this, you don't need to refresh your view while debugging your code.
Set 'Agent list selection' as trigger and Target = None.
Create a button in the view using the following formula (replace 'batch process' by your agent name):
#Command([ToolsRunMacro];"(batch process)")
Here's an example of the agent code on how you can check if pfstatus in selected docs is the same.
Option Public
Option Declare
Sub Initialize
Dim col As NotesDocumentCollection
Dim doc As NotesDocument
Dim vwUI As NotesUIView
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim dbcurrent As NotesDatabase
Set dbCurrent = session.currentdatabase
'Use vwui.documents to keep documents selected if the agent runs.
'Like this, a user can deselect a faulty document.
'Don't forget to deselect all docs at the end of your code
Set vwui = ws.Currentview
Set col = vwui.Documents
'If a user did not 'select' a document (eg V marker before the docline), but merely positioned on a document,
'you need to create a single doc collection based on the caretnoteid (= id of selected document)
If col.count = 0 And vwui.caretnoteid <> "" Then
Set doc = dbCurrent.Getdocumentbyid(vwui.caretnoteid)
Set col = dbCurrent.createdocumentcollection()
Call col.Adddocument(doc)
End If
'Get status from first document to get status to compare against
Dim statusRef As String
Set doc = col.getfirstdocument
If doc Is Nothing Then Exit Sub 'avoid error when no doc is selected
statusRef = doc.pfStatus(0)
'loop other selected documents to compare status
Set doc = col.getNextDocument(doc)
While Not doc Is Nothing
If doc.pfStatus(0) <> statusRef Then
'A document with another status is selected, so do not continue
Msgbox"Please choose only one Write Off selection!"
Exit sub
End If
Set doc = col.getNextDocument(doc)
Wend
'If code gets here, you can loop all documents again to do you batch processing
'Reset doc to first doc in selected collection
Set doc = col.getfirstdocument()
While Not doc Is Nothing
'... some code to run on current doc in the loop ...
Set doc = col.getNextDocument(doc)
Wend
'Deselect documents at the end of your code
Call vwui.Deselectall()
End Sub
Is PFStatus a multi-value field? If it isn't, it can never have more than 1 value (unless you set more than one value programmatically). Or is it a checkbox field?
I think it would be the best if you simply disallow the selection of documents from multiple categories in the view. See https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/H_ONSELECT_EVENT.html
IMHO a status field should never be directly input by the user. You should have buttons that guide the user to perform some functions AND change the status in the meantime.
I have two views which are Computer and Draft. I create a button in computer view and it is to create a copy of computer document to draft view.
Below is my button code. When I click the button, it said "Object variable not set"
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim view As NotesView
Set db = session.CurrentDatabase
Set view = db.GetView( "Draft" )
Set doc = dc.GetFirstDocument()
Set dc = db.AllDocuments
While Not (doc Is Nothing)
Call doc.CopyToDatabase(db)
Set doc = dc.GetNextDocument(doc)
Wend
End Sub
Can anyone help me? And can I ask, do I need to insert any formula inside Draft view? Thanks for any help!
Update Question
I have found the problem and fixed my code. But when I click the button, it copies all document and shows on both views. How can I want a copy of the document in Draft only selected document? For example, the "Active" document only? Thanks!
Views do not "contain" documents. Documents are in a database, and views show selected documents, using a SELECT formula. If your SELECT matches all documents, all documents will show up. That formula decides which documents are part of the view.
If view A contains your document and view B doesn't, you have to adapt the SELECT formula in view B so that it will match the document.
E.g. if you want your current document to show up in view B, you could add a value to the current document, like DocumentViews, and set it to "B", and set the SELECT formula of view B to SELECT DocumentViews="B".
Now, if you want to do something with the document that's currently selected in a view, you can use the NotesDatabase.UnprocessedDocuments property. It contains a list of all selected documents.
Dim ns As New NotesSession
Dim db As NotesDatabase
Set db= ns.CurrentDatabase
Dim dc As NotesDocumentCollection
Set dc= db.UnprocessedDocuments
Dim doc As NotesDocument
Set doc= dc.GetFirstDocument
Dim newdoc As NotesDocument
Do Until doc Is Nothing
' you might have to check the status of the current document before copying...
Set newdoc= doc.CopyToDatabase(db)
Call newdoc.ReplaceItemValue("Status", "Draft")
Call newdoc.Save(True, False)
Set doc= dc.GetNextDocument(doc)
Loop
I have an error on a computed for display text field.
For Each document, i open it in edit mode and resave to correct it.
I have the same problem on many databases and documents.
I tried to correct it with an agent over the entire base with the function EditDocument in uiworkspace . As follows:
Option Public
Option Declare
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim view As NotesView
Dim doccand As NotesDocument
Dim doc As NotesDocument
Dim result As Integer
Dim uiwks As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set db = session.Currentdatabase
Set col = db.Unprocesseddocuments
Set docCand = col.getfirstdocument
On Error Resume next
While Not docCand Is Nothing
Set uidoc = uiwks.Editdocument(True, docCand)
Call uidoc.save
Call uidoc.close(True)
Set docCand = view.getNextdocument(docCand)
Wend
End Sub
This function corrects the problem only when I start it from my Notes client. It does not work as a scheduled task in the domino server. I tried with computewithform without uiworkspace and it does not work either.
Anyone have a method to refresh with edit and save document in scheduled agent?
computed for display text field
Such type of fields are not saved in documents, it's kind of same thing as a Computed Text.
About your solution:
NotesUIWorkspace and EditDocument can't be use in a schedule agents that run in background (i.e. on server)but only from UI (that's why it works when you run LN).
What you need to do is to use ComputeWithForm method from NotesDocument. It will refresh documents in background (no need to open/save it).
While Not docCand Is Nothing
Call docCand.ComputeWithForm(False, False)
Call docCand.save
Set docCand = col.getNextdocument(docCand)
Wend
Notice, in your script there is an issue, you are trying to get next document from a view which is not initialized. I guess you want to use col instead.
Set docCand = view.getNextdocument(docCand)
Computed for display fields are not supposed to be saved. You should not have to do a refresh.
There is only one circumstance that I know of in which the value of a computed for display field is saved. It happens when the field on the form is originally designed as a regular computed field, but then someone changes it to computed for display. The original computed fields were saved as items in the stored document, and even after the field is changed to computed for composed Notes will continue to see the saved value. If that's what's happening, then what you really want to do is run an agent to delete the saved values. E.g.,
FIELD myFieldThatUsedToBeComputedButIsNowCFD := #DeleteField;
i have a doc with embedded view... in this embedded view i have a button that compile some code.
Inside this code i have Set Coll=db.unprocesseddocuments instructioin so when i select document inside this embedded view i think the collecion is composed by the document that i have select.
But the collecion contains the current uiwork documents instead the document that i have select inside the embedded view. Why ? How can i populate the collection with the selected document of the embedded view ?
With #command([toolsrunmancro];"MyAgent") instead the simply code inside the button the result is the same...
Someone can help me ?
This example works for me:
Action button "Test" in view (LotusScript)
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set col = db.UnprocessedDocuments
Set doc = col.GetFirstDocument
While Not doc Is Nothing
Print doc.UniversalID
Set doc = col.GetNextDocument(doc)
Wend
End Sub
The Embedded View properties are
After selecting documents in embedded view a click on action button "Test" prints all selected documents Universal ids.
I think the key to Knut's answer is that the button in question must be an action button within the embedded view, and not a button on the form.
I want to put a form ( document ) to EditMode = false; So, when the form is opened, I want to cannot modify any fields etc until I press a button that puts the doc. in EditMode = true.
My code is smth like this:
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = ws.CurrentDocument
'Set doc = uidoc.Document
uidoc.EditMode = False
End Sub
I choose to code in the Initialize method of the Form...
But it doesn't work and it gives me a message like: " Document comand is unavailable" . Please help, I will appreciate, thank you.
As a general rule of thumb, the Initialize event should not be used in forms. One reason for this is that the form has not necessarily finished loading everything by the time that Initialize runs.
This code should be placed in the QueryOpen event.
Another best practice is to NOT use NotesWorkspace.CurrentDocument to get a handle to the current form and instead use the Source parameter passed into the QueryOpen event. NotesWorkspace.CurrentDocument should only be used in agents and other places where the form is not already in context. Calling NotesWorkspace.CurrentDocument while the current document is already in context can cause strange behavior in Notes.
Here's some code that should work:
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
If (Not Source Is Nothing) Then Source.EditMode = False
End Sub