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
Related
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.
I have probably a very simple problem but got stuck on it
I have a form inside it i have a field and for it i want to take value from a embedded view has anybody a idea how to accomplish it.
Getting a value from an embedded view from the "surrounding" document is not possible. But the opposite direction definitely is.
In the code of all events / actions in the embedded view you can use the following code to get the surrounding document:
Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Then you could set fields on base of the currently selected document in the view e.g. in the event Onselect (new since Version 8) you could place some code like this (partly taken from Desiger help of event Onselect ):
Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Dim lastCaretID As Variant
lastCaretID = "000"
Set uidoc = ws.CurrentDocument
Sub Onselect(Source As Notesuiview)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
caretNoteID$ = Source.CaretNoteID
If lastCaretID <> caretNoteID$ Then ' we only process if the highlighted row has changed
lastCaretID = caretNoteID$
noteID$ = "NT00000" + caretNoteID$
Set doc = db.GetDocumentByID( caretNoteID$ )
Call uidoc.Document.ReplaceItemValue( "SelectedSubject", doc.GetitemValue( "Subject") )
End If
End Sub
Take care: Calling uidoc.Refresh / uidoc.Reload from within code in the embedded view context will most certainly crash your Notes- Client, so don#t do this...
As far as I know there is no easy way to do that in classic Notes. You may have to rethink your design/approach. I would use a picklist dialog box for this.
I am sure you can do that in XPages, or if this is a web application it would not be that difficult to do with Javascript/jQuery.
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 an issue with lotusscript developement.
Well, this is my scenario :
I designed a form named "FORM"
Create a new Document using the form "FORM"
The form "FORM" contains a RichText Field named "ListPod"
When opening the document in EDIT mode, I want to attach automatically a file (C:\Files\file.pdf) directly in the field "ListProd"
I used the event "OnLoad" to access the RichText Field and do my work.
My problem is that the field "ListProd" doesn't exist yet. Any idea please?
Here is my source :
Sub Onload(Source As Notesuidocument)
Dim fileName As String
fileName$ = Dir$( "c:\Files\*.pdf", 0 )
Print fileName$
If Not ( fileName$ = "" ) Then
Dim object As NotesEmbeddedObject
Dim rtItem As NotesRichTextItem
Set rtItem = Source.Document.GetFirstItem("ListProd")
If rtItem.Type = RICHTEXT Then
Set object = rtitem.EmbedObject(EMBED_ATTACHMENT, "", "c:\Files\"+fileName$)
End If
End If
End Sub
"rtItem.Type" Throws an error because "rtItem" is NULL. What can I do to access this field please ?
Thank you in advance
Use QueryOpen event and try to recreate your item using NotesRichTextItem constructor:
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim bIsNewDoc As Boolean
Set doc = Source.Document
bIsNewDoc = True
If Not Isnewdoc And Not doc Is Nothing Then
bIsNewDoc = doc.IsNewNote
End If
If Not bIsNewDoc And Mode% = 1 Then
'Your code
Call doc.RemoveItem("ListProd")
Set rtitem = New NotesRichTextItem(doc, "ListProd")
Call rtitem.EmbedObject(EMBED_ATTACHMENT, "", fileName$)
'Your code
End If
End Sub
I found a soluion here
Validate rich text fields for attachments without saving the UI document
Using : uidoc.refresh True, I could transfer All front-end modified information to back-end. And so, i've got access to my 'ListProd' field without saving :)
Hopr it helps you :)
I have documents in a folder that have a field AUNID which is filled with the unique id of a specific child doc. On the folder's action bar I have a button which is supposed to open the document related to the AUNID for editing by the user.
When the action button is pressed, it gives the user the following error:
Invalid UNID; UNID must be a 32-digit hex string.
After pressing 'Ok', however, the correct document opens for editing. I have used the debugger and the code is all executing exactly how I anticipate, however this error pops up for what seems like no reason.
Here is my code:
Sub Click(Source As Button)
On Error Goto handleError
Dim ws As New NotesUIWorkspace
Dim s As New NotesSession
Dim leaddoc As NotesDocument
Dim action As NotesDocument
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesUIDocument
Set db = s.CurrentDatabase
Set leaddoc = db.UnprocessedDocuments.GetFirstDocument
Set view = db.GetView("(ActionsByLead)")
If (leaddoc.GetFirstItem("AUNID").Text = "") Then
Msgbox ("There is nothing to edit!")
Exit Sub
End If
Dim uid As String
uid = Cstr(leaddoc.GetFirstItem("AUNID").Text)
Set action = db.GetDocumentByUNID(uid)
Call ws.SetTargetFrame("")
Call ws.EditDocument(True, action,,,, False) 'Error occurs on this line according to the debugger.
Exit Sub
handleError:
Resume Next
End Sub
Check the form of the child document that you are opening. I suspect there is something during the load of that document that is causing the error, and it isn't related to the action or the AUNID item on the parent document.
Or try creating a new child document and see if the error appears