Hi
I’m trying to write a generic piece of formula that can be put in a smart icon and re-used on any old database (ND6 client naturally).
Anyway, I’m not sure if I’m missing something on how to get the value of a field if the field name is a variable. I’ve tried @GetField but that’s only good if the list contains only one value, kinda useless when the whole idea is to work with lists.
Anyway here’s my code & I know it’s got problems !
tOptionList := “Overwrite List”: “Replace String in list”: “Add to end of List”;
tChoice := @Prompt([OkCancelList]: [NoSort]; “Field Changer”; “What type of field change would you like to make?”; “”; tOptionList);
@If(tChoice = “”; @Return(“”); “”);
tFieldName := @Prompt([OkCancelEdit]; “Field Name”; “Please enter the field name.”; “”);
@If(tFieldName = “”; @Return(@Prompt([Ok]; “Error”; “Please enter a field name”)); “”);
@If(
tChoice= “Overwrite List”;
@Do(
@If(@IsNull(@GetField(tFieldName)); continue := @Prompt([YesNo]; “New Field”; “Do you want to add the field " + tFieldName + " to the document”); continue := @True);
@If(continue; “”; @Return(“”));
tValue := @Prompt([OkCancelEdit]; “Field Value”; "Please enter the value for field " + tFieldName + “.”; “”);
@SetField(tFieldName; tValue )
);
tChoice= “Replace String in list”;
@Do(
@If(@IsNull(@GetField(tFieldName)); @Return(@Prompt([Ok]; “Error”; “The field you have selected does NOT exit in the document. Please use the overwrite function to create a new field on the document”)); “”);
tList := tList;
tValueReplace := @Prompt([OkCancelEdit]; “Field Value”; “Please enter the string you would like replaced in the " + tFieldName + " list.”; “”);
tValue := @Prompt([OkCancelEdit]; “Field Value”; “Please enter the string you would as the replacement in the " + tFieldName + " field.”; “”);
@Set(tList; @GetField(tFieldName));
@Prompt([Ok]; “list check”; tList);
@If(!@Contains(tList; tValueReplace); @Return(@Prompt([Ok]; “Error”; tValueReplace + " does not exist in " + tFieldName)); “”);
@Replace(tList; tValueReplace; tValue );
@SetField(tFieldName; tList )
);
tChoice=“Add to end of List”;
@Do(
@If(@IsNull(@GetField(tFieldName)); @Return(@Prompt([Ok]; “Error”; “The field you have selected does NOT exit in the document. Please use the overwrite function to create a new field on the document”)); “”);
tValue := @Prompt([OkCancelEdit]; “Field Value”; "Please enter the string you would like appended to the " + tFieldName + “'s list.”; “”);
@SetField(tFieldName; @GetField(tList) );
@SetField(tFieldName; tList: tValue)
);
“”)
Any thoughts or advice greatly appreciated! Once it’s working without problems, I’m going to post it up here as a handy tool for developers when having to fiddle with lists.
TIA
Steve