[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Agent using formula to simply find and replace from list on multiple docs

Posted on 2008-06-11
Medium Priority
Last Modified: 2013-12-18
Hi guys,

I have a categorised view
I want to allow users to select some docs and find and replace values in a field.
the field is a list and may contain one or more values.


select one or  more documents
hit action button
presented with list, lookup from view in same database
select one or cancel
presented with a 'change to' pop up string box
make change
do not allo more than 10 documents at one time (if possible)
do not present box for each document

I have so far this
list:=@Prompt([OkCancelListMult] ; "Select "; "choose" ; "" ; LOOKUP FROM VIEW; "" );
x := AFIELD;
y := @Replace(x; list;choice);
z := @Trim(y);
@SetField("AFIELD"; z);

Question by:tashsmith
  • 3
  • 2

Expert Comment

ID: 21760531
It should work.
Did I get it right, you want to get keyword list from view lookup and then let user to replace some of the values?

In this case, multi selection is not the best option, of course, option "OkCancelList" should be better. Unless you need to replace multiple choices with one.
Then we must clear resulting list from duplicate values using  @Unique.

Agent target should be "All selected documents".

You can simplify code, specifying just:
myList:=@Prompt([OkCancelList] ; "Select "; "choose" ; "" ; LOOKUP FROM VIEW; "" );
myChoice:= @Trim(ALLOW USER TO TYPE);
FIELD AFIELD:= @Trim(@Replace(AFIELD; myList; myChoice));

Open in new window

LVL 22

Expert Comment

ID: 21760555
Try this.
Create new action on your categorized view, choose Lotus Script, go to Options section of the action's code, right click and choose Import, select the file codeEE.txt, choose yes if prompted to replace existing code...

Haven't tested it, post away if something is wrong...

Hope this helps,

Author Comment

ID: 21760991
Hi guys,

Thanks for that, gotta run, will test and post back tomorrow:-)
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 21769038
Hi mbonaci:

I have tried your solution first as it appears to cater for more of my requirements, thanks.

On running the agent, nothing seems to be happening.

I have replaced the field and view names as requested in the markup.

There is no prompts and when the debugger is running it isnt evoking or stepping throuhg anything?
LVL 22

Accepted Solution

mbonaci earned 2000 total points
ID: 21769593
Here, I tested the solution and it was braking LotusScript's Replace function for no apparent reason.
So I changed it to avoid that function and simplified it in the process.

The example view is attached, but since the EE doesn't allow attaching nsf files, I've changed the extension to txt. Extract the file to Lotus\Notes\Data folder and rename extension back to nsf.
Double click the nsf, Notes opens, right click on tab and choose Open in Designer.
Then go to view - view action, there's the code. Start debugger, preview in Notes, select a couple of docs and click the action. Observe the code in action so that you can better understand what happens...

If I misunderstood something post the question...

Option Declare
Sub Click(Source As Button)
	On Error Goto ErrHandler
	Dim s As New NotesSession
	Dim w As New NotesUIWorkspace
	Dim db As NotesDatabase
	Dim c As NotesDocumentCollection
	Dim cur As NotesDocument
	Dim it As NotesItem
	Dim ret As Variant, newValue As Variant
	Const fldName = "HTTPHeaders"		'Change this to the name of the field that holds values you want to change
	Const viewName = "AllDocsNew"		'Change this to the name of the the view that displays values you want to change
	Const columnNumber = 1					'Change the number of column that displays the values
	Set db = s.CurrentDatabase
	Set c = db.UnprocessedDocuments
	If c Is Nothing Then Exit Sub
	If c.Count = 0 Then
		Msgbox "You have to select at least one document!", 16, "Warning"
		Exit Sub
	End If
	If c.Count > 10 Then
		Msgbox "The maximum number of selected documents is 10!", 16, "Warning"
		Exit Sub
	End If
	ret = dbColumn( db, viewName, Cint( columnNumber ), True, False )	'Get unique values from view's first column
	If Isempty( ret ) Then Exit Sub
	ret = w.Prompt( 7, "Select values to change", "Select one or more values to change.", ret(0), ret ) 'ask user to choose values he wants to change
	If Isempty( ret ) Then
		Messagebox "User canceled", , "No value selected"
		Exit Sub
	End If
	newValue = w.Prompt( 3, "New value", "Enter replacement value", "" )	'get new value from user
	If Isempty( newValue ) Then Exit Sub
	Set cur = c.GetFirstDocument
	Do Until cur Is Nothing
		Set it = cur.GetFirstItem( fldName )	'get the field that holds the values
		If Not it Is Nothing Then
			Forall el In ret	'Call replace sub for every string user selected to be changed
				Call ReplaceValueOfMultiItem( it, el, newValue )
			End Forall
			Call cur.Save( False, False )
		End If
		Set cur = c.GetNextDocument( cur )
	Exit Sub
	Msgbox "Error in action - Click" & Chr$(10) & "Line: " & Cstr( Erl ) & Chr$(10) & "Err No: " & Err & ": " & Error$
	Resume out	
End Sub
Function dbColumn( db As NotesDatabase, viewName As String, columnNo As Integer, flgUnique As Boolean, flgUseReplicaID As Boolean ) As Variant
	'Mbonaci, 30.08.2005.
	'Same as @DbColumn
	'Warning:		the return value is limited to 64K
	On Error Goto ErrHandler
	Dim s As New NotesSession
	Dim strDbPath As String, tmpFormula As String
	strDbPath = AdjustedFilePath( s, db )
	If flgUseReplicaID Then	
		tmpFormula = |@DbColumn( "" : "NoCache"; "| & db.ReplicaID & |"; "| & viewName & |"; | & columnNo & | )|
		tmpFormula = |@DbColumn( "" : "NoCache"; "| & db.Server & |" : "| & strDbPath & |"; "| & viewName & |"; | & columnNo & | )|		
	End If
	If flgUnique Then
		tmpFormula = |@Unique( | & tmpFormula & " )"
	End If
	dbColumn = Evaluate( tmpFormula )
	Exit Function
	Msgbox "Error in function - dbColumn" & Chr$(10) & "Line: " & Cstr( Erl ) & Chr$(10) & "Err No: " & Err & ": " & Error$
	Resume out	
End Function
Function AdjustedFilePath( s As NotesSession, db As NotesDatabase ) As String
    'Mbonaci, 19.01.2006
    'Function is used to prepare the path for LS dbColumn implementation
    'We need path relative to notes\data dir
	On Error Goto ErrHandler
	Dim datadir As String, fcPath As String, tmpPath As String
	dataDir$ = Lcase( s.GetEnvironmentString( "Directory", True ) )
	fcPath$ = Lcase( Left( db.FilePath, Len( datadir ) ) )
	If( fcPath = datadir ) Then
        'If the database is open and on the Notes workstation FilePath returns the complete path
        'for example, C:\Lotus\Notes\Data\Subdir1\Subdir2\dbName.nsf
		fcPath = Mid$( db.FilePath, Len( datadir ) + 2 )
		AdjustedFilePath = fcPath
	Elseif Instr( fcPath, "!!" ) Then
        'FilePath returns the server name (srvName!!path) when both of these cases are true:
        'FilePath is used in an agent running on a server
        'The NotesDatabase object was not obtained through the CurrentDatabase property of NotesSession
		tmpPath = db.FilePath
		AdjustedFilePath = Right( tmpPath, Len( tmpPath ) - Instr( tmpPath, "!!" ) - 1 )
        'If the database is on a Domino server, or closed on the Notes workstation
        'FilePath returns the path relative to the data directory (for example, sub\db.nsf)
		AdjustedFilePath = db.FilePath
	End If
    'Last we double all backslashes
	AdjustedFilePath = Replace( AdjustedFilePath, "\", "\\" )
	Exit Function
	Msgbox "Error in function - AdjustedFilePath" & Chr$(10) & "Line: " & Cstr( Erl ) & Chr$(10) & "Err No: " & Err & ": " & Error$
	Resume out
End Function
Sub ReplaceValueOfMultiItem( Item As NotesItem, ValueToRemove As Variant, ReplacementValue As Variant )
    'Mbonaci, 18.12.2006
    'Function replaces ValueToRemove with ReplacementValue in Item
	On Error Goto ErrHandler
	Dim ArrayV( ) As Variant
	Dim x As Integer
	Forall v In Item.Values
		Redim Preserve ArrayV( x )
		If v <> ValueToRemove Then
			ArrayV( x ) = v
			ArrayV( x ) = replacementValue
		End If
		x = x + 1
	End Forall
	Item.Values = ArrayV
	Exit Sub
	Msgbox "Error in Sub - ReplaceValueOfMultiItem" & Chr$(10) & "Line: " & Cstr( Erl ) & Chr$(10) & "Err No: " & Err & ": " & Error$
	Resume out
End Sub

Open in new window


Author Closing Comment

ID: 31466101
This works perfectly, and the instructions were concise, accurate and easy to follow.

Thanks very much

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question