Skip to Content
0

Set Default value in user defined field while adding used defined in Table

Apr 11, 2017 at 04:00 PM

67

avatar image

Hi.

I want to add user defined field with default value in database. User field is added successfully and it returns zero on adding field. But when i check in database, there is no default value set there. I'm setting default value as "GETDATE()" for date field. Default value remains empty in database.

Here is my code:
Dim v_UserField As SAPbobsCOM.UserFieldsMD 'v_UserField = goParent.goDICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields) 'v_UserField.TableName = "@IDH_ACTLOG" 'v_UserField.Name = "test1" 'v_UserField.Description = "test1" 'v_UserField.Type = SAPbobsCOM.BoFieldTypes.db_Date 'v_UserField.SubType = SAPbobsCOM.BoFldSubTypes.st_None 'v_UserField.Size = 10 'v_UserField.DefaultValue = "getdate()" 'Dim v_RetVal As Integer = v_UserField.Add() 'If v_RetVal = 0 Then ' com.idh.bridge.DataHandler.INSTANCE.doError("default value added successfully") 'Else ' com.idh.bridge.DataHandler.INSTANCE.doError("Failed to add default value") 'End If

fwerfw.png (191.4 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

DIEGO LOTHER Apr 11, 2017 at 10:30 PM
0

Hi Saad,

I believe there is no way to set a default value for a date with function like GETDATE(), you can just set a fixed date. :(

Kind Regards,

Diego Lother

Show 3 Share
10 |10000 characters needed characters left characters exceeded

But in SQL, we can put getdate() in default value while adding column in a table and it sets the current date while adding records if no value is provided.
Can't we put the getdate() function as default in a SQL column through API??
There is a property of default value. Then whats the purpose of this ???

0

Hi Saad,

Yes, in SQL Server is possible, but by the API I believe not. Maybe someone else in this board have some approach about this.

About the property default value on the API for a datetime field, only allowed to set a specific date. :(

Kind Regards,

Diego Lother

0

Hi Diego Lother,

Thank you for your views and help :)

0