Monday, 7 March 2011

Useful Edit Field Button

Here is some useful code that prompts for a field name, field value and field type.  If the field exists and has a value, it automatically defaults the new value to the existing value.

unid:= @Text(@DocumentUniqueID);

theField := @Prompt([OkCancelEditCombo]; "Change Field"; "Select Field";""; "":@DocFields);


currValueTemp:= @GetDocField(unid; theField);
currValue:= @If( @IsError(currValueTemp); "errorValue"; @Text(currValueTemp) );
theValue := @Prompt([OkCancelEdit]; "Change Field"; "New Value: use semicolon separator for lists."; currValue);

currType:= @If( @IsNumber(currValueTemp); "Number"; @IsTime(currValueTemp); "Time"; "Text" );
theType := @Prompt([OkCancelList]; "Change Field"; "Data Type"; currType; "Text" : "Time" : "Number" : "Text List" : "Number List" : "Time List" : "Delete Field");

@If(

theType = "Time";
@SetField(theField; @TextToTime(theValue));

theType = "Number";
@SetField(thefield; @TextToNumber(theValue));

theType = "Text List";
@SetField(theField; @Trim(@Explode(theValue;";")));

theType = "Number List";
@SetField(theField; @TextToNumber(@Explode(@Trim(@ReplaceSubstring(theValue;" ";""));";")));

theType = "Time List";
@SetField(theField; @TextToTime(@Explode(theValue;";")));

theType = "Delete Field";
@SetField(theField; @DeleteField);

@SetField(theField; @Text(theValue))
)

No comments:

Post a Comment