About This Code
Brief Description:
FieldSetter
Notes Version:
R4.x, R6.x, R8.x, R5.x, R7.x
Last Modified:
09 Dec 2009
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
This is a LS Agent I put in every database I own so I can quickly stamp all selected records with certain values without having to write a special agent when the need arises.
Option Public
Sub Initialize
Dim session As New notessession
Dim db As notesdatabase
Dim col As notesdocumentcollection
Dim doc As notesdocument
Dim uiWorkspace As New NotesUiWorkspace
Set db=session.currentdatabase
Set col=db.unprocesseddocuments
Set doc=col.getfirstdocument
Dim Fld As NotesItem
Dim FldCount As Integer
If db.currentaccesslevel < 5 Then ' Little Security Touch
Print ("Access Denied")
Beep
Beep
Beep
Beep
Beep
Beep
Beep
Exit Sub
End If
'Get list of field names
FldCount = 0
Forall item In doc.Items
FldCount = FldCount + 1
End Forall
Redim FieldList(0 To FldCount)
FieldList(0) = "-Create New Field-"
x = 0
Forall item In doc.Items
x=x+1
FieldList(x) = Cstr(item.name) ' Now FieldList is an array with all fieldnames
End Forall
Call Sort(FieldList) ' Now it's alphabetized
'Now to select which field to set
FieldToChange = UIWorkspace.Prompt(PROMPT_OKCANCELCOMBO, "---- Field Setter ----", "Please select wich field you wish to change.","" ,FieldList )
If Trim(FieldToChange) ="" Then
Print "Canceled"
Exit Sub
End If
If FieldToChange = "-Create New Field-" Then
FieldToChange = UIWorkspace.Prompt(PROMPT_OKCANCELEDIT, "---- Field Setter ----", "Enter the Field Name you wish to add","" )
If Trim(FieldToChange) ="" Then
Print "Canceled"
Exit Sub
End If
End If
'Now to get the New Value
NewFieldInput = UIWorkspace.Prompt(PROMPT_OKCANCELEDIT, "---- Field Setter ----", "Please Enter the new value.","" ,"" )
If Trim(NewFieldInput) ="" Then
Print "Canceled"
Exit Sub
End If
Set Thisitem = doc.GetFirstItem( FieldToChange )
If Not Thisitem Is Nothing Then
ThisType = Cint(Thisitem.type)
Else
DefaultChoice = ""
Redim TypeList(0)
TypeCount = -1
If Isdate(NewFieldInput) Then
TypeCount = TypeCount + 1
Redim Preserve TypeList(TypeCount)
TypeList(TypeCount) = "Date"
DefaultChoice = "Date"
End If
If Isnumeric(NewFieldInput) Then
TypeCount = TypeCount + 1
Redim Preserve TypeList(TypeCount)
TypeList(TypeCount) = "Number"
If DefaultChoice = "" Then DefaultChoice = "Number"
End If
TypeCount = TypeCount + 1
Redim Preserve TypeList(TypeCount)
TypeList(TypeCount) = "String"
If DefaultChoice = "" Then
ThisType =1280
Else
TypeChoice = UIWorkspace.Prompt(PROMPT_OKCANCELCOMBO, "---- Field Type ----", "What type of field do you wish this to be.",DefaultChoice ,TypeList )
If Trim(TypeChoice) ="" Then
Print "Canceled"
Exit Sub
End If
Select Case(TypeChoice)
Case "Date" : ThisType = 1024
Case "Number" : ThisType = 768
Case "String" : ThisType = 1280
End Select
End If
End If
Select Case ThisType
Case 1024 : NewFieldValue = Cdat(NewFieldInput)
Case 768 : NewFieldValue = Cdbl(NewFieldInput)
Case 1280 : NewFieldValue = Cstr(NewFieldInput)
Case Else : NewFieldValue = Cstr(NewFieldInput)
End Select
While Not doc Is Nothing
Call doc.replaceitemvalue(FieldToChange, NewFieldValue)
Call doc.save(False,False)
Set doc=col.getnextdocument(doc)
Wend
End Sub
Sub Sort(array)
n=Ubound(array)+1
For I=1 To (n-1)
J=I
Do While J>=1
If array(J)<array(J-1) Then
A=array(J)
A1=array(J-1)
array(J)=A1
array(J-1)=A
J=J-1
Else
Exit Do
End If
Loop
Next
End Sub
Usage / Example
When you run it, it will let you select the field you wish to stamp. Then You enter the new value.
So what good is this?
Do you have hundreds of tiny temporary agents used to clean up, mass stamp, make one little change?
Then you need this instead.