#GPPT Form Control Conditional Control of Window Fields

David Meego - Click for blog homepageGP Power Tools Form Control is a “No Code/Low Code” customization tool for Microsoft Dynamics GP. It can be used to solve many requirements without any coding (or with a small conditional script).

Here is an example showing how you can quickly use Form Control to conditionally control the User Defined fields on the Account Maintenance window.

In Microsoft Dynamics GP there are situations where you might want to disable, lock, or hide a field based on a business rule, or maybe change the background or font color for a field as a visual cue.

As this is a demonstration, we will use the Alias field on the Account Maintenance window to control the condition. If the Alias field has contents, we will apply the Form Control rules to the User Defined fields; and if the Alias field is empty, we will reverse the Form Control rules.

To make the demonstration easier to see, we will start by changing the caption of the field, from Alias to Alias Conditional, and defaulting the User Defined fields.

This requirement can be created with the Form Control module in a few minutes.

Changing the Field Caption

The FORM CONTROL CONDITIONAL Form Control ID is limited by the Base Settings Resource Filter to exactly the GL_Account_Maintenance form in the core dictionary (0).

The Change Field Caption rule is limited to fields containing “Alias”.

The Expression field contains the caption to use, replacing the existing caption. Without the optional semicolon, it will only replace, rather than find and replace.

Defaulting the Fields

The Default Field Value rule is limited to fields beginning with “User Defined” which includes the 4 User Defined Fields on the window, but also includes the prompts. So, we must also exclude any fields beginning with “User Defined Prompt”.

The Expression field contains the text to place in the fields and the Key Field List contains a semicolon separated list of any additional fields to clear after setting the default values to make sure that the window does not think it has been changed.

Now when the window opens, the Alias field’s caption has been changed and the User Defined Fields have been populated.

Clearing the User Defined 1 Field

The Clear Field Value rule is limited to fields containing “User Defined 1”.

The Key Field List contains the fields which define when the rule should be processed. In this case we are including the window’s key field “Account Index” and the field that the condition is based on, “Account Alias”. The Script ID field contains the script which will return whether to apply the rule or not.

Disabling the User Defined 1 Field

The Disable Field rule is limited to fields containing “User Defined 1” or fields containing “User Defined Prompt 1” so we include both the field and its prompt.

The Key Field List and Script ID are filled in the same as the previous rule. The Reverse action checkbox specifies what to do when the script condition is false; when unchecked, no action is performed, when checked the action is reversed. So, for this rule, the fields will be enabled.

Locking the User Defined 2 Field

The Lock Field rule is limited to fields containing “User Defined 2”.

The Key Field List, Script ID and Reverse action checkbox are filled in the same as the previous rule.

Hiding the User Defined 3 Field

The Hide Field rule is limited to fields containing “User Defined String 1” or fields containing “User Defined Prompt 3” so we include both the field and its prompt.

The Key Field List, Script ID and Reverse action checkbox are filled in the same as the previous rule.

Changing Background Color for User Defined 4

The Set Field Background Color rule is limited to fields containing “User Defined String 2”.

The Key Field List, Script ID and Reverse action checkbox are filled in the same as the previous rule. The Color Selection has been set to Red from the 16.7 million colors available.

Changing Font Color for User Defined 4

The Set Field Font Color rule is limited to fields containing “User Defined String 2”.

The Key Field List, Script ID and Reverse action checkbox are filled in the same as the previous rule. The Color Selection has been set to Blue.

Conditional Script

The Script ID used for the all the conditional rules has been added with a script, which will return true or false using the MBS_FormControl_Conditional variable, based on whether the Alias field has been entered or not.

Code Excerpt from FORM CONTROL CONDITIONAL Form Control Conditional Script

[code]
in integer MBS_FormControl_Dictionary;
in string MBS_FormControl_Form;
in string MBS_FormControl_Window;
in string MBS_FormControl_Field;
inout anonymous field MBS_FormControl_Value;
in boolean MBS_FormControl_Modified;
out boolean MBS_FormControl_Conditional;

local integer MBS_Status;
local string l_Account_Alias;

MBS_FormControl_Conditional = false;

{ Edit your code below here }

if MBS_FormControl_Modified then
call with name "MBS_Get_Window_Value_Modified" in dictionary 5261,
MBS_FormControl_Dictionary {Dict},
MBS_FormControl_Form {Form},
MBS_FormControl_Window {Window},
"Account Alias" {Field},
l_Account_Alias, MBS_Status;
else
call with name "MBS_Get_Window_Value" in dictionary 5261,
MBS_FormControl_Dictionary {Dict},
MBS_FormControl_Form {Form},
MBS_FormControl_Window {Window},
"Account Alias" {Field},
l_Account_Alias, MBS_Status;
end if;
if MBS_Status <> OKAY then
debug str(MBS_Status);
end if;

if not empty(l_Account_Alias) {Condition} then
MBS_FormControl_Conditional = true;
end if;

{ Edit your code above here }

[/code]

Note: The Developer Tools module must also be registered to be able to run Form Control Conditional Scripts.

Downloading and Installing

Download the example settings, import using the Project Setup window (without any project showing, select the path to the xml file and click Import):

The Form Controls will be active immediately when the affected windows are next opened.

More Information

For an introduction series for Form Control with step-by-step instructions see:

For more information see:

Hope you find this example useful.

David

This article was originally posted on http://www.winthropdc.com/blog.

Leave a Reply