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;
Related
I have a document, and copy of document. I use TagNo as unique ID for both documents.
I also have Status field to differentiate each document which is Active, Inactive, Draft, and Lock. I will explain below my document situation.
Below here are my document with two field; Tag No = PTagNo; Status = PStatus. The situation as below.
For Original document, the status is set Active. When copy is created, Original document will change to Lock, And Copy document status change to Draft. (For this I already achieve.)
After done editing, I will change status for Draft document and Original document. This happen when I save Draft document as "Complete". My Draft document will be Original document while my Original document will be Archived document. So for my Draft document, status will change to Active while Original Document, status will change to Inactive.(Not achieve yet).
I paste my save code as below.
Save and Complete
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim activeDoc As NotesDocument
Dim view As NotesView
Dim keys(1) As String
'// Set database and doc
Set db = session.CurrentDatabase
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
keys(0) = doc.PTagNo(0)
keys(1) = "Lock"
Set view = db.GetView("Computer")
vpswd = Inputbox$("Pls input code to save :")
If vpswd = "o" Then
Set activeDoc= view.GetDocumentByKey(keys, True)
If Not activeDoc Is Nothing Then
If activeDoc.PStatus(0) = "Lock" Then
activeDoc.DocumetId = doc.UniversalID
Call activeDoc.ReplaceItemValue("PStatus", "Inactive")
Call activeDoc.Save(True, False)
End If
End If
Call uidoc.FieldSetText("PStatus" , "Active")
Call uidoc.FieldSetText("SaveOptions" , "1")
Call uidoc.Save
Call uidoc.Close
Else
Msgbox "Wrong Code"
Exit Sub
End If
End Sub
So I use GetDocumentByKey for field ptagno but it show error "Object variable not set". Did I use wrong function?. Any help will be appreciated. Thanks!
The variable ptagno has not been set - therefore the "Object variable not set" error. You need to read the value from the field PTagNo and assign it to the ptagno variable - or use it directly. For instance like this:
Set activeDoc= view.GetDocumentByKey(uidoc.FieldGetText("PTagNo"))
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 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 am aware that you can exclude certain folders - but you have to name them. I need a view to show only the documents in the inbox, that doesn't need updating everytime we create a new folder.
Any help would be greatly appreciated!
:)
It is not possible directly. There are no formulas that would help you build a select statement to get documents that are only in the Inbox. However, you could have an agent run on a scheduled basis (maybe every 5-10 minutes) that would update documents and flag them if they are in the inbox. Your view would then just need to select documents that have that flag set.
Updated As umeli pointed out, the flag needs to be unset when documents are moved out of the Inbox. Here's a modified script:
For example:
Dim s as New NotesSession
Dim db as NotesDatabase
Dim view as NotesView
Dim doc as NotesDocument
Dim allEntriesInbox as NotesViewEntryCollection
Dim allEntriesFlagged as NotesViewEntryCollection
Set s = New NotesSession
Set db = s.CurrentDatabase
Set view = db.GetView("($Inbox)")
Set viewFlagged = db.GetView("IsInInboxView")
Set allEntriesInbox = view.AllEntries
Set allEntriesFlagged = viewFlagged.AllEntries
allEntriesFlagged.StampAll("IsInInbox", "")
allEntriesInbox.StampAll("IsInInbox, "1")
Your view (named "IsInInboxView" in this example) should have a selection formula of IsInInbox = "1"
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