No "Script Area" in Lotus Notes Agent editor - lotus-notes

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

Related

running mail doc, server link not working properly

Problem :
Using Agent run and send mail give a different link
Mail Contain a link which is not include database
I set it send to a yahoo mail
Sub Initialize()
Print"Agent:First Reminder for LateIn Reason started running at " & DateValue(Now()) & "," + TimeValue(Now())
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim LateInVw As NotesView
Dim LateInDocs As NotesViewEntryCollection
Dim LateEntry As NotesViewEntry
Dim LateDoc As NotesDocument
Dim StaffVw As NotesView, StaffDoc As NotesDocument
Dim MailDoc As NotesDocument
Dim rtBody As NotesRichTextItem
Dim sysdoc As NotesDocument, sysVw As NotesView
Dim AttVw As NotesView, Attdoc As NotesDocument
Set db=ss.Currentdatabase
Set sysVw=db.getview("($System Settings)")
Set sysdoc=sysvw.getfirstdocument
If sysdoc Is Nothing Then Exit Sub
Set LateInVw=db.getview("(Testing Late-In Time Records)")
Set StaffVw=db.getview("($Active Staff by ID)")
Set AttVw = db.Getview("($Effective Attendance Setting By ID)")
tdy=Datevalue(Now)
'get all time records for today
Set LateInDocs=LateInVw.Allentries
Set lateEntry=LateInDocs.getfirstentry
Do While Not LateEntry Is Nothing
Set LateDoc=LateEntry.Document
Set Attdoc=Attvw.Getdocumentbykey(LateDoc.TStaffID(0), True)
If Attdoc.LateAtt(0)="Yes" Then
If LateDoc.LateReason(0)="" Then
If Not ApprovedLateIn(LateDoc, LateDoc.TAmend(0), False) Then
'get staff mail
Set staffDoc=StaffVw.Getdocumentbykey(LateDoc.TStaffID(0), True)
If Not staffdoc Is Nothing Then
'send email with link to main menu
If email$<>staffDoc.email(0) Then
' email$=staffDoc.email(0)
email$="chee111385#gmail.com"
Set Maildoc=New NotesDocument(db)
Set maildoc=db.Createdocument()
maildoc.Form="First Reminder Notification"
maildoc.Subject="Smartcard Attendance System: Late-In Notification for " +Format$(LateDoc.TDate(0),"dd/mm/yyyy")
Maildoc.StaffName=staffDoc.StaffName(0)
maildoc.Sendto="chee111385#gmail.com"
' maildoc.NotifyDate=LateDoc.Tdate(0)
maildoc.NotifyTime=Timevalue(LateDoc.TAmend(0))
maildoc.NotesServer=sysdoc.ServerPath(0)
maildoc.NotesDBPath=sysdoc.DBPath(0)
maildoc.send(True)
End If
End If
End If 'check against unimas's jadual kedatangan
End If 'check for late in reason
End If 'check late-in on/off in attendance settings
Set LateEntry=LateInDocs.Getnextentry(LateEntry)
Loop
End Sub
I will attach my image file and coding here
from this 2 image you can see that, actually i want to put as a
notes://Mulu/SmartCard Attedancce/sas-server.nsf/Scais Main?OpenFrameset
but result of the mail send out is
notes:////Scais Main?OpenFrameset
which is no server and database. I am not sure what part of my coding is wrong
Another attachment will be the form i use as mail.form
First of all: Sending an external mail with a custom form like you do it is not the best Idea, as the target system might not be able to render everything accordingly.
That said, I would first create a document that contains all data and then RENDER it to a maildoc. code would look like this:
Dim Templatedoc as NotesDocument
Dim body as NotesRichtextItem
Set Templatedoc=New NotesDocument(db)
Set Templatedoc=db.Createdocument()
Templatedoc.Form="First Reminder Notification"
Templatedoc.StaffName=staffDoc.StaffName(0)
' maildoc.NotifyDate=LateDoc.Tdate(0)
Templatedoc.NotifyTime=Timevalue(LateDoc.TAmend(0))
Templatedoc.NotesServer=sysdoc.ServerPath(0)
Templatedoc.NotesDBPath=sysdoc.DBPath(0)
Set maildoc=New NotesDocument(db)
maildoc.Form = "Memo"
maildoc.Subject="Smartcard Attendance System: Late-In Notification for " +Format$(LateDoc.TDate(0),"dd/mm/yyyy")
maildoc.Sendto="chee111385#gmail.com"
Set body = New NotesRichtextItem( maildoc, "Body" )
Call Templatedoc.RenderToRTItem( body )
maildoc.send(True)
Second: You set two fields (NotesServer and NotesDBPath) to compute your Link. But your link in reality is computed from environment- variables, and these are not set on the server.
Change your Link- Computation- Formula to:
srv := NotesServer;
pth := NotesDBPath;
That should do the trick for the link.

how to access textfield value in lotus script for Domino designer

I am new to Domino designer and lotus script,
I tried to access my text field by:
Sub Click(Source As Button)
Dim myText As String
myText = Inputbox("insert some text :","Testing Heading","Default value test",100,100)
Msgbox "you have entered : "+myText
[myfield].text = myText //error
End Sub
but it shows an error:
named product field does not exist
Googled for it but can't find the solution.
One more, searched for tutorials for creating forms,views,database in domino designer for beginners. But can't find one.
If possible please provide links to tutorial sites.
EDIT 1:
Sub Click(Source As Button)
Dim myText As String
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim enteredText As String
myText = Inputbox("insert some text :","Testing Heading","Default value",100,100)
Msgbox "you have entered : "+myText
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
doc.addrfield = myText
enteredText = doc.addrfield
Msgbox "Data entered in addrfield : "+ enteredText //error
End Sub
Error:
Object variable not set
EDIT 2:
#Knut
In Domino Designer, how database tables can be created ?
I mean something like create table <tablenam> (field1,feild2,..);
How can I access it. I refered this. This guy showed me how how to connect to database but did't show how to create DB table.
You have to use the LotusScript Notes classes to
get the current open UI document
get the corresponding back-end document
set the item (=field)
Your example would look like this then:
Sub Click(Source As Button)
Dim myText As String
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
myText = Inputbox("insert some text :","Testing Heading","Default value",100,100)
Msgbox "you have entered : "+myText
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
doc.myField = myText
End Sub
You could use doc.ReplaceItemValue instead. It gives you a bit more flexibility.
The Designer help file itself gives you an introduction to Notes development in chapter "Application Design".

Lotus notes - refering to a doc. from a NotesDocumentCollection

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

Calling script library in agent and button

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 )

Filter Process script Library

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.

Resources