CHANGECOMPANY Function (RecordRef)
Redirects references to table data from one company to another.
[Ok :=] RecordRef.CHANGECOMPANY([CompanyName])
The RecordRef that refers to the record that you want to access from a table in another company.
Type: Text or code
The name of the company to which you want to change. If you omit this parameter, you change back to the current company.
Property Value/Return Value
true if the company was found; otherwise, false.
If you omit this optional return value and the company cannot be found, a run-time error occurs. If you include the return value, you must handle any errors.
When executing this function, the user's access rights are respected. For example, a user cannot access data in CompanyName unless he already has the necessary access rights.
Global filters always belong to a specific company. If you use the following code to select the company named NewCompany, any filters assigned to RecordRef will be transferred to RecordRef in the new company.
Even if you run the CHANGECOMPANY function, triggers still run in the current company, not in the company that you specified in the CHANGECOMPANY function.
This example shows how to use the CHANGECOMPANY function. The following code takes a RecordRef to table 18 Customer in the current company and redirects it to the table in another company (in this case Company B). The last record in the Customer table of Company B is then deleted.
This example requires that you create the following variables and text constant in the C/AL Globals window
|Text constant name||DataType||ENU value|
|Text000||Text||Record to be deleted: %1|
MyRecordRef.OPEN(18); MyRecordRef.CHANGECOMPANY('Company B'); MyRecordRef.FINDLAST; RecID := MyRecordRef.RECORDID; MESSAGE(Text000, RecID); MyRecordRef.DELETE;