Using system settings to define values that might change
The example shown in Setting default values embeds values directly into JavaScript code. This makes it difficult to maintain values that might change over time. It is often the case that a better solution can be achieved by using system-wide settings.
System-wide settings are available from the Administration Setup area. You can create fields for the Settings object as you do for any other object definition. The difference is that only one Settings record exists per tenant. Values from that record can be used in various templates, formulas, etc.
To use system settings, let's make some changes to the example shown in Setting default values:
- From the application switcher, select Setup Home.
- Click Settings under Administration Setup
- Click Configure:
The object definition page for Settings opens.
- Create three Currency fields for the Settings object: Admiral Fee, Captain Fee, and Sailor Fee. Set a default value for each of these fields (default values can be changed later). See Adding fields for information about adding fields to an object definition.
- Modify the above script to use values from the Settings record
instead of hard-coded values as shown below:
<script> function cust_membFee() { with (document.theForm) { if (membership_fee.value=='') { var code = membership_type.options[ membership_type.selectedIndex].getAttribute('code'); if (code=='A') membership_fee.value='{!#SETTINGS.admiral_fee}'; else if (code=='C') membership_fee.value='{!#SETTINGS.captain_fee}'; else membership_fee.value='{!#SETTINGS.sailor_fee}'; } } } </script>