Solved

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

Posted on 2008-06-11
6
531 Views
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.

so

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
FIELD AFIELD:= AFIELD;
list:=@Prompt([OkCancelListMult] ; "Select "; "choose" ; "" ; LOOKUP FROM VIEW; "" );
choice:=ALLOW USER TO TYPE;
x := AFIELD;
y := @Replace(x; list;choice);
z := @Trim(y);
@SetField("AFIELD"; z);
SELECT @All

0
Comment
Question by:tashsmith
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:olaraak
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

0
 
LVL 22

Expert Comment

by:mbonaci
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,
mb¤
codeEE.txt
0
 

Author Comment

by:tashsmith
ID: 21760991
Hi guys,

Thanks for that, gotta run, will test and post back tomorrow:-)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:tashsmith
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?
0
 
LVL 22

Accepted Solution

by:
mbonaci earned 500 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...

Mb¤
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 )
	Loop
	
out:
	Exit Sub
ErrHandler:
	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 & | )|
	Else		
		tmpFormula = |@DbColumn( "" : "NoCache"; "| & db.Server & |" : "| & strDbPath & |"; "| & viewName & |"; | & columnNo & | )|		
	End If
	
	If flgUnique Then
		tmpFormula = |@Unique( | & tmpFormula & " )"
	End If
	
	dbColumn = Evaluate( tmpFormula )
	
out:
	Exit Function
ErrHandler:
	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 )
		
	Else
        '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, "\", "\\" )
	
out:
	Exit Function
ErrHandler:
	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
		Else
			ArrayV( x ) = replacementValue
		End If
		x = x + 1
	End Forall
	
	Item.Values = ArrayV
	
out:
	Exit Sub
ErrHandler:
	Msgbox "Error in Sub - ReplaceValueOfMultiItem" & Chr$(10) & "Line: " & Cstr( Erl ) & Chr$(10) & "Err No: " & Err & ": " & Error$
	Resume out
End Sub

Open in new window

ReplaceValueOfMultiValueItem.zip
0
 

Author Closing Comment

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

Thanks very much
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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