Record.ChangeCompany([Text]) Method

Version: Available or changed with runtime version 1.0.

Redirects references to table data from one company to another.

Syntax

[Ok := ]  Record.ChangeCompany([CompanyName: Text])

Parameters

Record
 Type: Record
An instance of the Record data type.

[Optional] CompanyName
 Type: Text
The name of the company to which you want to change. If you omit this parameter, you change back to the current company.

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.

Remarks

When executing this method, the user's access rights are respected. For example, a user cannot access data in CompanyName unless they already have the necessary access rights.

The ChangeCompany method is not affected by the Reset Method (RecordRef). You can deselect a company by making a new call to ChangeCompany or by using the Clear Method.

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.

Record.ChangeCompany(NewCompany);  

Even if you run the ChangeCompany method, triggers still run in the current company, not in the company that you specified in the ChangeCompany method.

Example

This example shows how to use the ChangeCompany method. The following code takes a Customer record 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.

codeunit 50112 ChangeCompany
{
    trigger OnRun()
    var
        RecID: RecordID;
        MyRecord: Record Customer;
        Text000: Label 'Record to be deleted: %1';
    begin
        MyRecord.ChangeCompany('Company B');  
        MyRecord.FindLast;  
        RecID := MyRecord.RecordId;  
        Message(Text000, RecID);  
        MyRecord.Delete;  
    end;
}

Record Data Type
Get Started with AL
Developing Extensions