Setting default value on a field?

2019-08-03 17:38发布

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!

2条回答
你好瞎i
2楼-- · 2019-08-03 18:16

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.

查看更多
神经病院院长
3楼-- · 2019-08-03 18:17

Try to override initValue method in your table. Give code, for example :

public void initValue()
{
  this.TestDefaultValue = 1;
}

Hope this help

查看更多
登录 后发表回答