SBM JavaScript Library Guide → JavaScript Examples → Setting Field Properties Based on Field Values
To recreate these examples, your application should contain the following fields and they should be added to your custom form:
Field type |
Database name |
Display name |
Values |
---|---|---|---|
Single Selection |
REQUEST_TYPE |
Request Type |
Billable Nonbillable |
User |
ACCOUNT_MANAGER |
Account Manager |
Users assigned to roles specified for this field or added as values for the field in SBM Application Administrator. |
Text |
SOW_NUMBER |
SOW Number |
Specified by users. |
Binary |
SALES_APPROVAL |
Sales Approval |
Yes No |
User |
SALES_MANAGER |
Sales Manager |
Users assigned to roles specified for this field or added as values for the field in SBM Application Administrator . |
In this example, you can set the Account Manager and SOW Number fields as required when users select Billable from the Request Type field. If another value is selected from the Request Type field, the Account Manager and SOW Number fields are removed from the form, and are made optional.
function RequestTypeChanged() { var text = GetFieldValue("REQUEST_TYPE"); if (text == "Billable") { MakeFieldRequired("ACCOUNT_MANAGER", true); MakeFieldRequired("SOW_NUMBER", true); } else { HideField("ACCOUNT_MANAGER"); HideField("SOW_NUMBER"); MakeFieldOptional("ACCOUNT_MANAGER", false); MakeFieldOptional("SOW_NUMBER", false); } } AddChangeCallback("REQUEST_TYPE", RequestTypeChanged);
In this example, you can set the Account Manager and SOW Number fields as required and display the Sales Approval field when users select Billable from the Request Type field. If another value is selected from the Request Type field, the Account Manager, SOW Number, and Sales Approval fields are removed from the form, and Account Manager and SOW Number fields are made optional. In addition, when users select Yes in the Sales Approval field, the Sales Manager field appears on the form. If another value is selected, the Sales Manager field is removed from the form. Note: The Sales Approval field must be a drop-down list. It cannot be a radio button or a check box.
function RequestTypeChanged() { var text = GetFieldValue("REQUEST_TYPE"); if (text == "Billable") { MakeFieldRequired("ACCOUNT_MANAGER", true); MakeFieldRequired("SOW_NUMBER", true); ShowField("SALES_APPROVAL"); } else { HideField("ACCOUNT_MANAGER"); HideField("SOW_NUMBER"); HideField("SALES_APPROVAL"); MakeFieldOptional("ACCOUNT_MANAGER", false); MakeFieldOptional("SOW_NUMBER", false); } } AddChangeCallback("REQUEST_TYPE", RequestTypeChanged); function SalesApprovalChanged() { var text = GetFieldValue("SALES_APPROVAL"); if (text == "Yes") { ShowField("SALES_MANAGER"); } else { HideField("SALES_MANAGER"); } } AddChangeCallback("SALES_APPROVAL", SalesApprovalChanged);
Copyright © 2007–2016 Serena Software, Inc. All rights reserved.