Solved

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

Posted on 2008-06-11
6
527 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lotus Domino - LKMgr Long Held Lock Dump 10 2,696
Lotus notes "Estimate" form to Quickbooks invoice 2 346
Why the url within notes is no action 6 45
@Mailsend 3 41
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now