How To: Set a field's default value |
Article Type | How To |
Title | Set a field's default value |
| <i>How do I set the default value for a field?</i><br>
<br>
The answer to this question depends on whether you want to set a default value regardless of where inserts are made from or if your default value is view-specific.<br>
<br>
<br>
To set a default value regardless of how data is inserted into a table, write a script in the table's <a href="http://support.dataweb.com/Help/default.view?Topic=DataWebscript/dataclasses/wsdataclasscreate">BeforeInsert Data Class</a>.<br>
<br>
For example, to set the default value of the <span class="smallCode">state</span> field to "WA":<br>
<br>
<span class="smallCode">// If the user does not specify a state, set state to WA<br>
if ( !record.state ) { record.state = "WA"; }</span><br>
<br>
<br>
To set a default on a specific view form, write a <a href="/default.view?Topic=views/vaddingscripts">script on that view</a> inside a dataregion. Make sure you place the htmlblock <i>before</i> the field whose default value you're setting.<br>
<br>
<span class="smallCode"><ws:htmlblock displaymodes="insert"><br>
<!--#record.state = "WA";#--><br>
</ws:htmlblock><br>
<br>
<ws:field name="state" displaymodes="insert"><ws:caption>State:</ws:caption></ws:field></span> |
Last Reviewed | February 20, 2015 14:08:26 |
|