Question

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.

Était-ce utile?

La solution

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

Autres conseils

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 )
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top