this code is for change company id ,no??
1.I delete the second if statement:
EUKMatrixRole   matrixToDuplicate = eukMatrixRole::findByMatrixId(_matrixIDToDuplicate);
   eukSecurityTreeNode = null;
   eukSecurityTreeNodeEdit = null;
   /*if(matrixToDuplicate.dataAreaId== CompanyId)
   {*/
       while select crossCompany eukSecurityTreeNode where eukSecurityTreeNode.EUKMatrixRole == matrixToDuplicate.recId
       {
          info(strFmt("role %1",eukSecurityTreeNode.EUKMatrixRole));
              eukSecurityTreeNodeEdit = EUKMatrixRoleHelper::dulpicateTreeNode(eukSecurityTreeNode,_matrix.recId,_matrix.MatrixRoleVersion);
       }
2.findByMatrixId method:
       eukMatrixRole.selectForUpdate(_forUpdate);
       if(_matrixID)
      {
       select firstonly  crossCompany eukMatrixRole
       where eukMatrixRole.MatrixID == _matrixID;
      }
       return eukMatrixRole;
3.dulpicateTreeNode method :
select forUpdate  eukSecurityTreeNode;
      try
      {
       ttsBegin;
       eukSecurityTreeNode.clear();
       eukSecurityTreeNode.data(_node);
       eukSecurityTreeNode.EUKMatrixRole = _matrixId;
       eukSecurityTreeNode.EUKMatrixRoleVersion = _versionId;
       eukSecurityTreeNode.insert();
       ttsCommit;
      }
      catch
      {
       error("@EUK481");
       ttsAbort;
      }
      return eukSecurityTreeNode;
but I don'tknow where I will set the changeCompany because I get this error message :
"
Insertion operations are not allowed between companies. The changecompany password allows you to change the current company before inserting the record."