问题
I'm adding a new field to an existing Table (not a "core" one, but one that was created by an inhouse dev previously) and I'm trying to set a default value for it.
I created a field of type Int, but now by default it's all 0's for the records that are already there.
Is there any way to define a default value for that field, for all the existing records and to be inserted records ?
Ultimately, what I'm trying to achieve is that I want a configurable field (ShowOnReport) so certain records won't show up in a Web Report. Right now, I want this field to default to 1 to all existing records, and later, switch them to 0 depending on business needs.
Maybe I've got the termininology wrong, but Google and Bing are mute to me regarding this... :(
Thanks!
回答1:
From your description I think your field should be of type NoYesId
which is similar to a boolean but is rendered as a check box per default.
For a default value you should overwrite the table method initValue
and set your field to NoYes::Yes
- this ensures the default value for all new records. For your existing records you have to write a simple AOT Job which sets NoYes::Yes
to your field via update_recordset
.
回答2:
Try to override initValue method in your table. Give code, for example :
public void initValue()
{
this.TestDefaultValue = 1;
}
Hope this help
来源:https://stackoverflow.com/questions/20293147/setting-default-value-on-a-field