Can someone offer some help on this? I'm getting an 'invalid key value type' error when trying to search a view using the userName variable as a key.
Is this because it's the NotesName type? Is there any way to get around this? Any help appreciated. Thanks!
%REM
Sub aiv_checkPersonIsValid
Description:
Checks that the person(s) that have been entered into the location database are valid
members of the CCL Address Book
Function calls: N/A
Sub calls: N/A
Called in event: onChange (to populate fields)
Called in action: Save and Close, Save, Save And Add Another
Called by: co_countValuesAndPopulate()
%END REM
Public Function aiv_checkPersonIsValid (userName As NotesName) As Boolean
Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim peopleDb As NotesDatabase
Dim peopleView As NotesView
Dim peopleDoc As NotesDocument
Dim thisDoc As NotesDocument
Dim uidoc As NotesUIDocument
Dim key(0) As Variant
Dim noMatchFound As String
Let noMatchFound = "No match found for this name. Please choose a name from the menu provided."
Dim PersonNameField As NotesItem
'Dim userName As NotesDocument
Set uidoc = w.CurrentDocument
Set thisDoc = uidoc.Document
'get handle to People database and check we've found the database
Set peopleDb=s.GetDatabase("****", "ccl\development\LocSysPeople.nsf")
If Not peopleDb Is Nothing Then
'get handle to view in People database and check we've found the view
Set peopleView = peopleDb.GetView("All\LocSysLookup")
If Not peopleView Is Nothing Then
'Make the PersonNameField variable equal to the value of the first item in the Person Name Field
Set PersonNameField = thisDoc.GetFirstItem("PersonName")
ForAll pName In PersonNameField.Values
'Start to loop through the PersonNameField and check that the names chosen exist in the people database
'lookup record in People database which matches the name in the PersonName field on this document
Set userName = New NotesName(pName)
Set key(0) = userName
'Set peopleDoc = peopleView.GetDocumentByKey(uidoc.Document.GetItemValue("PersonName")(0), True)
Set peopleDoc = peopleView.GetDocumentByKey(key, True)
'If there is no match found to the document in the peopleDb, show a MsgBox
If peopleDoc Is Nothing Then
MsgBox "No match found in the CCL People Database for '" + pName.Common + "'. Please choose a valid name.", 0, "Error: No match found"
aiv_checkPersonIsValid=False
Exit Function
End If
'End Loop
End ForAll
End If
End If
End Function
You seem to be using the userName variable multiple times for different purposes, once in the function definition and then changing the type later in the code. The code looks like it was ripped from a different function and adapted because the value being passed in it not the one your comparing in the code later, there is also nothing to set the return value of the function which is another error
Here's how I would write that function
Public Function aiv_checkPersonIsValid As Boolean
aiv_checkPersonIsValid=False
Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = w.CurrentDocument
Dim thisDoc As NotesDocument
Set thisDoc = uidoc.Document
Dim userName As NotesName
Dim peopleDoc As NotesDocument
Dim PersonNameField As NotesItem
'get handle to People database and check we've found the database
Dim peopleDb As NotesDatabase
Set peopleDb=s.GetDatabase("****", "ccl\development\LocSysPeople.nsf")
If Not peopleDb Is Nothing Then
'get handle to view in People database and check we've found the view
Dim peopleView As NotesView
Set peopleView = peopleDb.GetView("All\LocSysLookup")
If Not peopleView Is Nothing Then
'Make the PersonNameField variable equal to the value of the first item in the Person Name Field
Set PersonNameField = thisDoc.GetFirstItem("PersonName")
ForAll pName In PersonNameField.Values
'Start to loop through the PersonNameField and check that the names chosen exist in the people database
'lookup record in People database which matches the name in the PersonName field on this document
Set userName = New NotesName(pName)
Set peopleDoc = peopleView.GetDocumentByKey(userName.Abbreviated, True)
'If there is no match found to the document in the peopleDb, show a MsgBox
If peopleDoc Is Nothing Then
MsgBox "No match found in the CCL People Database for '" + pName.Common + "'. Please choose a valid name.", 0, "Error: No match found"
Exit Function
End If
End ForAll
aiv_checkPersonIsValid = true
End If
End If
End Function
Related
I have two document which is original and copy document. When I save copy, original will changes status too.
Follow up by my other question Save copy document and change status field for copy document and original document using lotusscript button. Below are my code.
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
I already set variable and successfull saved. When I saved, Copy document is saved and change status to Active, but for Current document which currently with "Lock" status, did not change to "Inactive" status. Can anyone help me? Is there any error that I have made inside coding? Your help really appreciate. Thanks!
I've solved this question. For my problem, I do not set TagNo as my first column. So I need to created new view with two column which is TagNo and Status. Set both column as ascending.
My goal is to create a document from one database in another database and fill the fields with values from the source database. I was able to connect to the other database and compose a document but editing is not possible.
Sub Click(Source As Button)
Dim mydb As NotesDatabase
Dim workspace As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim Server As String
Dim DBPath As String
Dim DBForm As String
'-----------------------------------------------------------------
' Set target database information
'-----------------------------------------------------------------
Server = "Server"
DBPath = "Path"
DBForm = "Form"
'-----------------------------------------------------------------
' Attempt connection to target server
'-----------------------------------------------------------------
Print "Connecting to target database"
Set mydb = New NotesDatabase("", "")
Call mydb.Open(Server, DBPath)
If (mydb.IsOpen) Then
'-----------------------------------------------------------------
' Create new document
'-----------------------------------------------------------------
Print "Connection established to: " + mydb.FileName
Set workspace = New NotesUIWorkspace
Print "Composing change management record"
Set uidoc = workspace.ComposeDocument (Server, DBPath, DBForm)
Call uidoc.FieldSetText("FIELD", "12345")
Else
Msgbox "Warning: unable to open target database."
End If
End Sub
When I'm calling
Call uidoc.FieldSetText("FIELD", "12345")
I'm getting an error message saying that I have to open the document in edit mode. When I'm trying to change the edit mode with
uidoc.EditMode = True
I'm getting the error message "Document command is not available". Can someone please help me here?
it is possible, take the backend not the frontend classes
Dim workspace As New Notesuiworkspace
Dim session As New NotesSession
Dim myDb As NotesDatabase
Dim doc As notesdocument
Set myDb= session.Getdatabase("Server", "Path", false)
If (mydb.IsOpen) Then
Set doc = myDb.Createdocument()
doc.field="12345"
Call workspace.Editdocument(true, doc)
Else
Msgbox "Warning: unable to open target database."
End If
I need the functionality described here: Determining which folder contains a document in Lotus Notes without using the LotusScript FolderReferences property
It says: "And the following code in the Script Area". But there's no script area. There's a tree containing "Document Selection", "(Options)", "Declarations", "Initialize", and , "Terminate".
You can enter that code into the body of the Initialize method. Make sure to keep the code that automatically appears when you select Initialize and just enter the code in the middle
Sub Initialize
Dim session As New notessession
Dim db As notesdatabase
Dim doc As notesdocument
Dim doc2 As notesdocument
Dim view As notesview
Dim noteid1 As String
Dim noteid2 As String
Dim item As notesitem
Dim collection As notesdocumentcollection
Set db=session.CurrentDatabase
Set collection=db.UnprocessedDocuments
Set doc=collection.getfirstdocument
noteid1=doc.NoteID
Forall v In db.Views
If v.isfolder Then
Set doc2=v.GetFirstDocument
While Not doc2 Is Nothing
noteid2=doc2.NoteID
If noteid1=noteid2 Then
Messagebox v.name
End If
Set doc2=v.getnextdocument(doc2)
Wend
End If
End Forall
End Sub
I have a view which on top there is a button called Delete
I want to delete all the selected documents from the view; for this I used:
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim database As NotesDatabase
Dim documentCollection As NotesDocumentCollection
Set database=session.CurrentDatabase
Set documentCollection=database.UnprocessedDocuments
If documentCollection.Count=0 Then
Msgbox "No documents selected ",,"warning"
Else
userChoice=Msgbox ("Delete" & Cstr(documentCollection.Count) & " documents?",64+100, _
"Confirm...")
If userChoice=6 Then
Call documentCollection.RemoveAll(True)
Call workspace.ViewRefresh
End if
But, what if I want to delete only some docs ( from all selected docs. from view ) which have let say Value = YES where Value is a text field inside the document?
I tried declaring:
Dim ui As NotesUIDocument
Dim doc As NotesDocument
Set doc=ui.document
But I get the message: Object variable not set. So I guess I have to refer to a document using the NotesDocumentCollection? How?
Thanks for your time!
Your Error Message has nothing to do with your question... The Error Message comes from setting doc form an unitialized uidoc. You need to have a Set ui = ws.CurrentDocumentsomewhere in your code, and of course declare ws: Dim ws as New NotesUIWorkspace
But for your question you don't need an ui- document at all. To delete just some of the selected documents, you cycle through the collection and delete just the documents that match your criteria:
Dim doc as NotesDocument
Dim nextDoc as NotesDocument
Set doc = documentCollection.GetFirstDocument()
While not doc is Nothing
Set nextDoc = documentCollection.GetNextDocument(doc)
if doc.GetItemValue( "Value" )(0) = "Yes" then
call doc.Remove(True)
end if
Set doc = nextDoc
Wend
Or you reduce the collection to just contain the documents that match your criteria and then delete the whole collection:
Call documentCollection.FTSearch("[Value] = Yes",0)
Call documentCollection.RemoveAll()
But take care: The collection is reduced with a FTSearch, that might also get "Yes of course" or "Ye" depending on the setting of the FT Index of the database -> Not very reliable.
You need to loop through the documents in the document collection and then process them individually. Here's an example loop that uses your documentCollection variable:
Dim doc As NotesDocument
Set doc = documentCollection.GetFirstDocument
While Not(doc Is Nothing)
' Do stuff
' Get next document
Set doc = documentCollection.GetNextDocument(doc)
Wend
I have a form called Approver in "Approver" db.
The form has two editable text fields: Office and Group. It also has a dialog list field superior1.
The superior1 dialog list field should show the staff details filtered based on office & group:
if office = TSP & group = HR from the approver form, then shud filter the staffs based on these fields group" & "office" with the "Staff info" view of another database "TSP_Staff" and show in superior1.
But it is not getting filtered for me. :(
I am new to this tech, so I am confused and have no one to help me in this. This is the script I used:
for the superior1 field:
Sub Entering(Source As Field)
Dim s As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim uidoc As NotesUIDocument
Dim doc As Notesdocument
Dim work As New NotesUIWorkspace
Dim workspace As New NotesUIWorkspace
Dim sname As String
Dim consr As String
Dim cview As notesview
Set db = s.CurrentDatabase
Set uidoc = work.CurrentDocument
Set uidocs = workspace.currentdocument
Set cview = db.getview("(Application)")
'etype = uidoc.FieldGetText("Office")
'ftype = uidoc.FieldGetText("Group")
etype = "TSP"
ftype = "TSP1-G"
If(etype <> "" And ftype <> "") Then
Call filter
End If
Set view = db.getview("(x_search_staff)")
Set doc = view.GetDocumentByKey (uidoc.fieldgettext("Superior1"),True)
If doc Is Nothing Then
Msgbox "There is no previous transaction please select new trasaction.", 16, "Information"
Call uidoc.FieldClear("Superior1")
Call uidoc.gotofield ("Group")
Call uidoc.gotofield ("Office")
continue = False
Exit Sub
End If
Call uidoc.Refresh
End Sub
from the script library ...
Sub filter
Dim s As New notessession
Dim w As New notesuiworkspace
Dim uidoc As notesuidocument
Dim doc As notesdocument, newdoc As notesdocument, d As notesdocument, dd As notesdocument
Dim doc1 As NotesDocument, newdoc1 As NotesDocument
Dim dc As notesdocumentcollection
Dim bc As notesdocumentcollection
Dim view As notesview, v As notesview
Dim db As notesdatabase
Dim nextdoc As NotesDocument
Dim cview As notesview
Dim cnview As NotesView
Dim get_db As New notesdatabase(gsserver2, gspath2 & "Master\TSP_Staff.nsf")
Set db = s.currentdatabase
Set view = get_db.getview("(Staff Info)")
Set cview = db.getview("(x_search_staff)")
Set cnview = db.getview("(x_superior)")
Set uidoc=w.CurrentDocument
'To delet searched previous datas from form2 ----------------------------------------
Print "Please wait ..."
key = "Approver2"
Set v = db.getview("(x_delete_2)")
Set dc = v.GetAlldocumentsByKey(key,True)
'Set bc = v.GetAlldocumentsByKey(key,True)
'Call bc.RemoveAll(True)
Call dc.RemoveAll(True)
Call cview.Refresh
Call view.Refresh
Call cnview.Refresh
Call v.Refresh
'To start searching process based on Superior1 --------------------------------------
'f1= uidoc.FieldGetText("Office")
f1= uidoc.FieldGetText("Group")
'f1 = "TSP1-G"
Set dc = view.getalldocumentsbykey(f1, True)
'Set bc = view.getalldocumentsbykey(f2, True)
For b =1 To dc.count
Set doc = dc.getnthdocument(b)
Set newdoc = doc.copytodatabase(db)
'For c =1 To bc.count
'Set doc1 = bc.getnthdocument(b)
'Set newdoc1 = doc.copytodatabase(db)
If doc.form(0) = "Approver" Then
'If doc1.form(0) = "Approver" Then
newdoc.form = "Approver2"
'newdoc1.form = "Approver2"
'End If
End If
newdoc.save True, True
' Next
'newdoc.save True, True
'Next
Call w.viewrefresh
Call cview.Refresh
Call v.Refresh
Call cnview.Refresh
Call view.Refresh
Print "Process Completed....."
End Sub
if u got another way for this requirement temme in stepwise wat to do... or else... chk out ma script for errors... hope u help me :( today due date for this task...
I'm not sure how smart it is to filter the documents shown in a view by deleting documents from a database :)
My suggestion is to first post the code properly. This is simply unreadable.
How to display only subset of documents in your dialog list?
Create a hidden field on your form (you'll fill it with values you want displayed in the list using your code).
And then, on your dialog list field properties, second tab, set choices option to be "Use formula for choices" and set it to be the hidden field name.
Ask if you need more help...
Your code is very hard to follow, but if I understand your intention and parts of the filter function (does it even compile?) you could replace all of the code with this #dblookup-based formula in "use formula for choices" section of superior1 properties:
#dblookup("":"ReCache";"ServerName":"foo\Master\TSP_Staff.nsf";"(Staff Info)";Group;NameOfInterestingField);
You might want to add a #sort and/or #unique around it if the view contain duplicate values, and you might want to add the keyword [FAILSILENT] if some groups should result in an empty list.
An even simpler method could be to configure superior1 to use view dialog for choices.