I have existing document on a form called “ABC”. I would like to change the documents form to new form called “XYZ”.
Only documents with field type = metal, mining, cement change to new form.
How to write agent to replace old form to new form in the selected documents.
Thanks
Subject: Write Agent to change document form
For performance reasosn, I would suggest that you create a view where you show all documents. The first column would be the form name, the second one would be the type value.
You then use the GetAllEntriesByKey method of the NotesView class to get a NotesViewEntryCollection.
Then iterate through that collection using the GetFirstEntry and GetNextEntry methods.
For each view entry, use the ColumnValues property to get the value in the second column (remember, ColumnValues is zero-based, i.e. you should use ColumnValues(1) to get the second column).
Now you can check if the value matches any of the types where you want to change the form name. Again, for performance reasons I would create a list of all values (e.g. replaceType) where the form should be replaces, with both listtag and value set to the same value. You can then use IsElement to compare the one column value against all values in one call:
If IsElement(replaceType(entry.ColumnValues(1))) Then
If the IsElement function returns true, get the NotesDocument from the view entry, change the form using the ReplaceItemValue method and then save the document.
Subject: RE: Write Agent to change document form
Dear Karl, Thanks for your reply.
Subject: Write Agent to change document form
A one-line formula is all you need.
Assuming type is a single-valued field, and you want to change the Form if it matches any one of the values (metal, mining, or cement) then this will do the trick.
FIELD Form := @If((Form=“ABC”) & (Type=“metal”:“mining”:“cement”); “XYZ”; Form );
If type is multi-valued, then you’ll need to clarify your requirement because I can’t tell if you need it to match any one of the values (metal, mining, cement), all of them but in any order, or all of them in the specific order.
-rich
Subject: RE: Write Agent to change document form
Dear Rich, thanks for the formula. It works perfectly.