cancel
Showing results for 
Search instead for 
Did you mean: 

database

Former Member
0 Kudos

hi ,

How to get the data base or tables with the creation of Addon?

Regards,

MTR

Accepted Solutions (1)

Accepted Solutions (1)

former_member191896
Active Participant
0 Kudos

Hi MTR,

You can create DB tables/columns using the metadata objects like UserTablesMD, UserFieldsMD etc. Refer to SDK Help.

For coding details, you can also refer to this SDK sample

..\SAP Business One SDK\Samples\COM DI\CSharp\02.MetaDataOperations

Alternatively, you can use B1DE Tool (B1 Development Environment) to generate the code for your AddOn. This includes the code for creation of user defined Tables and Fields as well.

Regards

Aravind

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi thippareddy,

You can do it any way you want.

Some people create the Tables/Fields from B1, some have a separate applications that check's and, if needed, creates the user Tables and Fields.

Myself I have a function that checks and updates the database structure every time the add-on is run by the "manager" user. I then check if my UDO exist. If not it creates all the tables, fields, keys, permissions trees from XML files with the following content.

XML to create a User Table


<BOM>
	<BO>
		<AdmInfo>
			<Object>153</Object>
		</AdmInfo>
		<OUTB>
			<row>
				<TableName>TABLE_NAME</TableName>
				<Descr>TABLE_DESCRIPTION</Descr>
				<ObjectType>TABLE_TYPE</ObjectType>
			</row>
		</OUTB>
	</BO>
</BOM>

TABLE_TYPE can be 0 - No Object; 1 - Master Data Header; 2 - Master Data Rows; 3 - Document Header and 4 - Document Rows.

XML to create a User Field


	<BO>
		<AdmInfo>
			<Object>152</Object>
		</AdmInfo>
		<CUFD>
			<row>
				<TableID>@TABLE_NAME</TableID>
				<AliasID>FIELD_CODE</AliasID>
				<Descr>FIELD_DESCRIPTION</Descr>
				<TypeID>FIELD_TYPE</TypeID>
				<EditType></EditType>
				<Dflt></Dflt>
				<EditSize>15</EditSize>
			</row>
		</CUFD>
		<UFD1>
		</UFD1>
	</BO>

FIELD_TYPE can be A - alphanumeric; D - Date/Time; N - Numeric; B - Units and Measurments, etc.

EDIT_TYPE is the field sub-type, like: D user fields can have no EDIT_TYPE which creates a Date field or they can have a T EDIT_TYPE which creates a Time field.

XML to create a user key


	<BO>
		<AdmInfo>
			<Object>193</Object>
		</AdmInfo>
		<OUKD>
			<row>
				<TableName>@TABLE_NAME</TableName>
				<KeyName>KEY_UID</KeyName>
				<UniqueKey>N</UniqueKey>
			</row>
		</OUKD>
		<UKD1>
			<row>
				<ColAlias>KEY_FIELD_1</ColAlias>
			</row>
			<row>
				<ColAlias>KEY_FIELD_2</ColAlias>
			</row>
		</UKD1>
	</BO>

You can also register the UDOs with XML, but prefer doing it by code.

Regards,

Vítor Vieira