15. Writing a Template Assistant : How You Can Ensure Compatibility Between the Assistant and ApplyTemplate : Example—ApplyTemplate Compatibility
 
Share this page                  
Example—ApplyTemplate Compatibility
In this example, the frame template assistant procedure from the previous example has been modified for use with the ApplyTemplate utility. The difference between this example and the previous one is that the procedure must place the dynamically generated trim field inside of the top-level composite field of the frame template.
For this example, assume that the $_TopComposite macro variable of the frame template has been assigned a value of FreetrimComposite.
First, the parameters are defined:
Procedure Create_Dyn_Fld
(
fs = FrameSource 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, a text trim field is created and loaded with the specified text string:
trim_field = freetrim.create();
trim_field.textvalue = text_string.value;
Finally, the procedure must assign a value to the return code parameter and attach the composite field to the form. Because the trim field must be assigned to the frame template's top composite field, a recursive search procedure is called to search for a composite field with the name FreetrimComposite. When it is found, the trim field is added to that composite:
topcomposite = callproc
    find_top_composite(fs.topform);
trim_field.ParentField = topcomposite;
return_code = ER_OK;