OpenNTF.org - FieldRenamer
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
FieldRenamer 
Rating:
Rating: 5 , Number of votes: 1 
Contributor:
Tim Paque 
Category:
Lotusscript 
Type:
Utilities 
Document Release:
1.0 
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 LS agent lets you rename fields on selected documents


This is an agent I use a great deal when rewriting an old application when a field name or many field names need to be changed to something more useful or appropriate


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

FldCount = 0
x=0

'Get list of field names
Forall item In doc.Items
FldCount = FldCount + 1
End Forall
Redim FieldList(0 To FldCount)
Forall item In doc.Items
x=x+1
FieldList(x) = Cstr(item.name) ' now FieldList is an array with all fieldnames
End Forall

'Get list of field names
FldCount = 0
Forall item In doc.Items
FldCount = FldCount + 1
End Forall
Redim FieldList(0 To FldCount)
FieldList(0) = "-Unlisted 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 fields
FieldToChange = UIWorkspace.Prompt(PROMPT_OKCANCELLISTMULT, "---- Field Renamer ----", "Please select wich fields you wish to Rename.","" ,FieldList )
If Isscalar(FieldToChange) Then
Print "Canceled"
Exit Sub
End If
If FieldToChange(0) = "-Unlisted Field-" Then
FieldToChange(0) = UIWorkspace.Prompt(PROMPT_OKCANCELEDIT, "---- Field Deleter ----", "Enter the Field Name you wish to Rename","" )
If Trim(FieldToChange(0)) ="" Then
Print "Canceled"
Exit Sub
End If
End If

Redim Newlist(Lbound(FieldToChange) To Ubound(FieldToChange))
For z = Lbound(FieldToChange) To Ubound(FieldToChange)
Newlist(z) = UIWorkspace.Prompt(PROMPT_OKCANCELEDIT, "---- Field ----", "Please Enter the new Field Name. for the field: " & FieldToChange(z),"" ,"" )
Next

While Not doc Is Nothing
For y= Lbound(FieldToChange) To Ubound(FieldToChange)
If Doc.HasItem(FieldToChange(y)) Then
Set DeadField = doc.GetFirstItem(FieldToChange(y) )
Call DeadField .CopyItemToDocument( Doc, Newlist(y) )
Call DeadField.Remove
End If
Next

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
On the "Purchase" Form, the field for total sale is Total_Sale
On the "Lease" Form the field for total sale is totalsale

Now? Do you really want to tweak every view that shows these two forms together to show a field based on the form of the document? Its going to be slooowwwww.

Instead change the form, and use this agent on the existing records, to make both forms the same.
 Comments

No documents found

 Add your comment!