Archive for the ‘SnTT’ Category

h1

Dynamically loading subforms

April 17, 2008

I’m sure many Notes developers have gone through this problem before: “I want to load a different subform after the form is loaded”. Unfortunately, Notes doesn’t let you do that, and so ways have to be found around this… layers, hide/whens, sections, programmatic tables, etc.

But let’s say you reeeeaallllyyy want to dynamically load a subform, for example, when the user selects a value from a dropdown box. Here’s a way of doing it, supposing the default subform is “sfm_Default” and the subform you want to load comes from that dropdown box.

1. Make your computed subform take the value of whatever’s on a computed field (called for example fld_WhichSubform)

2. Put the following code on a button that should be called (via JS for example) when the dropdown box (called for example fld_DropDown) value changes:

@SetProfileField( “fm_FakeProfile”; “fld_PSubForm”; fld_DropDown; @UserName );
@Command( [ViewSwitchForm] ; Form )

(Any unique key that will correctly identify the document will do for the @SetProfileField. @Username is but a suggestion, @text( @DocumentUniqueID ) could be used as well)

3. Give the following formula to your fld_WhichSubform computed field:

x := @GetProfileField( “fm_FakeProfile” ; “fld_PSubform”; @text( @DocumentUniqueID ) );
@If( @IsError( x ) | x = “” ; “sfm_Default”; x )

This is but a simple example, and more interesting/complex things can be done with it.

Note: for this method to work, the document has to be saved. A @Command( [FileSave] ) before the ViewSwitchForm might be necessary in some circumstances.