Database.CopyCompany(Text, Text) Method

Version: Available or changed with runtime version 1.0.

Creates a new company and copies all data from an existing company in the same database.


[Ok := ]  Database.CopyCompany(SourceName: Text, DestinationName: Text)


This method can be invoked without specifying the data type name.


 Type: Text
The name of the company that you want to copy data from.

 Type: Text
The name of the company that you want to create and copy data to. The company name can have a maximum of 30 characters. If the database collation is case-sensitive, you can have one company called COMPANY and another called Company. However, if the database is case-insensitive, you cannot create companies with names that differ only by case.

Return Value

[Optional] Ok
 Type: Boolean
true if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.


Links and notes on records are not copied to the new company.

With versions 17.5 and later, errors in COPYCOMPANY can't be trapped. This change prevents a company from being partially copied when an error occurs and it's followed by a COMMIT(). Any error in COPYCOMPANY ends the execution flow, even with statements like: IF NOT CopyCompany(.., ..) THEN. Also, any COMMIT() in triggers or event subscribers is ignored.


The following example is based on the Copy Company batch job, which is part of the CRONUS. The batch job takes the Company system table as a data item and uses the Name field as the value of the SourceName parameter. The value of the DestinationName parameter is specified in the New Company Name field in the request page, which is represented by the NewCompanyName variable.

CopyCompany(Name, NewCompanyName);  

See Also

Database Data Type
Get Started with AL
Developing Extensions