I got an error 'Document command is not available' when the program hits the uidoc.Copy line. I have researched this error message. But all I get is only if it has anything to do with Edit Mode and I am not using that at all here.
Sub Click(Source As Button)
' ===========================================================
' Get common username, mail server, and mailfile information
to be used on ComposeDocument method
Dim session As New NotesSession
Dim reg As New NotesRegistration
Dim user As String
reg.RegistrationServer = "Test"
user = session.CommonUserName
Call reg.GetUserInfo(user, _
mailserver$, _
mailfile$)
' ======================================================================
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Call uidoc.GotoField("QSContactEMail")
Call uidoc.SelectAll
Call uidoc.Copy
Set uidoc = workspace.ComposeDocument _
(mailserver$, mailfile$, "Memo")
Call uidoc.GotoField("Subject")
Call uidoc.Paste
End Sub
You don't need to use copy and paste to transfer values from one document to another. You can directly assign those values using document objects.
There are several methods to do this- here is one that is similar to yours. Replace everything below the second line with this:
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument, newuidoc as NotesUIDocument
Set uidoc = workspace.CurrentDocument
Set newuidoc = workspace.ComposeDocument _
(mailserver$, mailfile$, "Memo")
Call newuidoc.FieldSetText("Subject", uidoc.FieldGetText("QSContactEMail"))
End Sub
Check to see if you have a field called $KeepPrivate set to "1". It will prevent copying.
The error can also happen if nothing is selected. Try STOP just before the line and make sure it is highlighted.
There are also other conditions listed here:
http://www-01.ibm.com/support/docview.wss?uid=swg21094450
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.
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 want to use the following script library in button and also in agent.
My script library code:Validate
Option Public
Option Declare
Dim Sess As NotesSession
Dim currentDb As NotesDatabase
Dim dataDb As NotesDatabase
Dim doc As NotesDocument
Dim workspace As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim rtitem As NotesRichTextItem
Sub Initialize
Set Sess = New NotesSession
Set currentDb = Sess.CurrentDataBase
Set workspace = New NotesUIWorkspace
Set uidoc = workspace.CurrentDocument
End Sub
Function ValidateForm ( Source As NotesUIDocument) As Boolean
On Error GoTo e
Set doc=source.Document
Dim Txt As String
Dim trimmed As string
txt = doc.Name(0)
trimmed = Trim(Txt)
If ( trimmed = "") Then
MsgBox "Please enter some text."
source.GotoField("Name")
ValidateForm= false
Else
ValidateForm= True
End If
Exit Function
e:
MsgBox "error at"& Erl() & " and error is "& Error()
End Function
In Button:
In button when i call the script library since in the validateform function it has source as notesuidocument and in button click it has souce as button it i giving me error.
Sub Click(Source As Button)
End Sub
I have tried using in agent in options using below:
Use "Validate"
and tried calling it in button using formula
#Command([ToolsRunMacro]; "Val")
But no use I am not getting the desired output.
I am new to lotus notes.Please help me in doing above tasks.
You don't need to take a parameter at all. In the initialize- Sub of your Script- Library you already set the global variable "uidoc" to the currently opened document:
Set workspace = New NotesUIWorkspace
Set uidoc = workspace.CurrentDocument
In your Function "validateForm" you simply omit the parameter and then replace "source" with "uidoc"
Set doc=source.Document
The other possibility (if you want to give the current document as a parameter):
Sub Click( Source as Button)
Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument
set uidoc = ws.CurrentDocument
Call ValidateForm( uidoc )
End If
Or if you keep the initialize code in your Library:
Sub Click( Source as Button)
Call ValidateForm( uidoc )
End If
This works, as "uidoc" is a global variable, that is already initialized by the Sub initialize of your Script- Library.
HTH
Make it an agent, not a script library. If it's named Validate, use that formula you had in the button without trying to include a script library.
#Command([ToolsRunMacro]; "Validate")
Script libraries are typically used for subroutines and functions that you will call from multiple agents or other scripts, not for entire agents. You can call an agent from a button or allow users to click on it in the Action menu or any number of other ways of calling it. You don't have to put it in a script library.
You could reduce the code in the agent to be as follows:
Option Public
Option Declare
Sub Initialize
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim Txt As String
Dim trimmed As string
Set uidoc = workspace.CurrentDocument
On Error GoTo e
Set doc=uidoc.Document
txt = doc.Name(0)
trimmed = Trim(Txt)
If ( trimmed = "") Then
MsgBox "Please enter some text."
uidoc.GotoField("Name")
End If
exit sub
e:
MsgBox "error at"& Erl() & " and error is "& Error()
End Sub
Or, if all you want to do is verify that a field is not empty and shift focus to that field, just add the following to any field's Input Validation formula:
#If ( #ThisValue = ""; #Failure ( "You must enter a value for " + #ThisName ); #Success )
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
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.