Wednesday, April 7, 2010

Renaming fields with formula agents

Put the code below in a formula agent. Set the old field names in the _fieldNamesFrom-list, and the new field names in the _fieldNamesTo-list. Not sure if it works correctly for NotesRichTextItems, but it should work on the other field types.

If there isn't a field with the old fieldname, a new one isn't created (in case you need to run the agent multiple times -> doesn't blank the new fields).

_fieldNamesFrom := "silly_fieldname" : "tpyo_fieldname";
_fieldNamesTo := "crazy_fieldname" : "correct_fieldname";

@For( i := 1 ; i <= @Elements( _fieldNamesFrom ) ; i := i + 1 ;
 _valueFrom := @GetField( _fieldNamesFrom[i] );
 @If( _valueFrom = "" ; "" ; @SetField( _fieldNamesTo[i] ; _valueFrom ) );
 @SetField( _fieldNamesFrom[i] ; @Unavailable )
);
SELECT @All

I post this as much for myself as for you, as I tend to delete the renaming agents after they've done their duty.

0 comments: