15. Writing a Template Assistant : How You Can Write an Assistant : Example—Field Template Assistant
 
Share this page                  
Example—Field Template Assistant
In this example, a field template assistant procedure has been designed to customize a field template.
The field template consists of a composite field that contains several entry fields and one text field for the title. The field template assistant procedure prompts the user for the title and assigns that text string to the text field of the composite field.
First, the parameters are defined:
Procedure Create_Label
(
ff = FormField not null,
return_code = integer not null,
batch_mode = integer not null
)=
Because the procedure must support batch mode, a default string is specified. Otherwise, the user is prompted for the string:
if batch_mode = TRUE then
text_string.value = 'Hello, world!';
else
status  = curprocedure.replypopup(messagetext =
'Enter text string.',
reply = text_string);
if status != PU_OK then
return_code = ER_FAIL;
return;
endif;
endif;
Next, the text field with the variable name "label" is loaded with the specified text string:
field_obj = CompositeField(ff).FieldByName(name =
        'label');
EntryField(field_obj).textvalue = text_string.value;
Finally, the procedure needs to assign a value to the return code parameter:
return_code = ER_OK;