Solved

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

Posted on 2008-06-11
6
519 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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi guys,

Thanks for that, gotta run, will test and post back tomorrow:-)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:tashsmith
Comment Utility
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
Comment Utility
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
Comment Utility
This works perfectly, and the instructions were concise, accurate and easy to follow.

Thanks very much
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

8 Experts available now in Live!

Get 1:1 Help Now