Reg Exp
Web Design
Notes Client
Edit Any Field SmartIcon
Inside the Notes client, I have an "Edit Any Field" SmartIcon. It pops up a list of all the fields on the currently selected document and allows you to edit the value or delete the field. Since it's a SmartIcon, it works in any database on any server (assuming you have access to the document). I originally found this code on the web for R5, but I've updated it for 6. I've also added the ability to add new fields, which wasn't there in the original code. And the original code only allowed for a colon separator if you're using multiple values - my version allows you to choose your separator (so your values could actually have a colon in it).

First, create a new smart icon. Go to File | Preferences | Toolbar Preferences. A window will pop up. Choose the "Customize" tab. Choose the toolbar you want to update (I chose "Universal" so it will always appear) and add a new button. Find an icon (the choices come from bookmark.nsf, so you can add a new one there if you don't have one to choose from) and give it a title. Here's the code:

NOTE: This code is Notes 6 specific (it uses @Eval and also reassigns a variable inside a statement) so only use it in your Notes 6 client.

REM {Get a listing of all the fields on the current document};
List := @DocFields;

REM {Possible data types to choose from.};
REM {I called Number Integer because use keyboard to select what you want with keyboard quicker.};
DataTypes := "Text" : "Date" : "Integer" : "Password" : "Name" : "Common Name" : "**** Remove Field ****" : "Text Multi Value" : "Date Multi Value" : "Integer Multi Value" : "Name Multi Value";

REM {Prompt for which field needs to be updated.};
EditField := @Prompt([OkCancelList]; "Select Field To Update"; "Select the field you wish to update:"; ""; List : "**** ADD A NEW FIELD ****");

REM {If adding a new field, prompt for the field name};
NewFieldName := @If(EditField = "**** ADD A NEW FIELD ****"; @Prompt([OkCancelEdit]; "Enter Field Name"; "Enter the name of the new field:"; ""); "");
CheckFieldName := @If(@IsMember(NewFieldName; List) & NewFieldName != ""; @Return(@Prompt([Ok]; "Already In List"; "The field " + NewFieldName + " already exists on the document.")); "");
UpdateVariable := @If(NewFieldName = ""; ""; EditField := NewFieldName);

REM {Prompt for which data type you would like the data to be};
REM {This needs to be done before value prompt to determine if the};
REM { Picklist or any prompting needs to be used.};
DataType := @Prompt([OkCancelList] : [NoSort]; "Choose Data Type"; "Please Select the correct data type or action for field: " + EditField; "Text"; DataTypes);

REM {For multi-valued fields, let the user choose the separator to use};
Separator := @If(@Contains(DataType; "Multi Value"); @Prompt([OkCancelList] : [NoSort]; "Choose Separator"; "Choose the separator to split out your multiple values"; ":"; (":" : ";" : "+" : "-" : "*")); "");

REM {Pull out the current value of the field};
CurrValue1 := @Eval(@Text(EditField));
CurrValue2 := @Abstract([TextOnly]; 254; ""; @Text(EditField));
CurrValue := @If(@IsNumber(CurrValue1) | @IsTime(CurrValue1); @Implode(@Text(CurrValue1); Separator); CurrValue2 != ""; CurrValue2; @Implode(@Text(CurrValue1); Separator));

REM {Based on what type of data is being entered different prompts will happen if any at all.};
RawValue := @If(
   @Contains(DataType; "Name Multi Value"); @PickList([Name]);
   @Contains(DataType; "Name"); @PickList([Name] : [Single]);
   DataType = "**** Remove Field ****"; "";
   @Contains(DataType; "Multi Value"); @Prompt([OkCancelEdit]; "New Value"; "Please enter the new desired value for: " + EditField + " seperated with " + Separator + " for each value."; CurrValue);
   @Prompt([OkCancelEdit]; "New Value"; "Please enter the new desired value for: " + EditField + "."; CurrValue)

REM {If data conversion doesn't work then don't set field.};
   DataType = "Date"; @If(@SetField(EditField; @TextToTime(RawValue)));
   DataType = "Integer"; @If(@IsError(@TextToNumber(RawValue)); ""; @SetField(EditField; @TextToNumber(RawValue)));
   DataType = "Password"; @SetField(EditField; @Password(RawValue));
   DataType = "**** Remove Field ****"; @SetField(EditField; @DeleteField);
   DataType = "Text Multi Value"; @SetField(EditField; @Explode(RawValue; Separator));
   DataType = "Date Multi Value"; @SetField(EditField; @TextToTime(@Explode(RawValue; Separator)));
   DataType = "Integer Multi Value"; @If(@IsError(@TextToNumber(@Explode(RawValue; Separator))); ""; @SetField(EditField; @TextToNumber(@Explode(RawValue; Separator))));
   DataType = "Name Multi Value"; @SetField(EditField; @Explode(@Name([Canonicalize]; RawValue); Separator));
   @SetField(EditField; RawValue)

I'll let you look through the code, but here's a quick overview: Get the list of fields. Prompt for the field to update, including the choice of adding a new field. If adding, prompt for the field name and make sure it doesn't already exist. Prompt for the data type of the field. If multiple value, prompt for the separator. Get the current value off the document. Prompt for the new value, with the current value as a default. Update the document.