web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to duplicate table in 2 differents companies?

(0) ShareShare
ReportReport
Posted on by 932

Hi,

I have function that tell me to duplicate table but when I change the company I can't do the duplication :  

this imy function :

duplication.png

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to duplicate table in 2 differents companies?

    Does your code ever go to the second if statement? How is your find method implemented? You need to specifically use crossCompany keyword to select records from different companies.

    Please share more information about what problems you encounter. "I can't do the duplication" contains no information.

  • BASMA Profile Picture
    932 on at
    RE: How to duplicate table in 2 differents companies?

    the code never go to the second if statement

    1.I have tree :

    matrix.png

    I want to create another tree based on this so I need to duplicate the table which saves the information from tree.

    2.

    matrix.png

    this interface let me choice which tree to duplicate.

    my problem is when the id of company of the tree to duplicate is different to the current company.

    I hope that you understand me now.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to duplicate table in 2 differents companies?

    Like I said you need to use the crossCompany keyword in your select statement if you want to find records in other companies.

    docs.microsoft.com/.../cross-company-x-code-basics

  • BASMA Profile Picture
    932 on at
    RE: How to duplicate table in 2 differents companies?

    I used cross company in select statement ,but My problem is why the code don't go to the second if statement

    if(matrixToDuplicate.dataAreaId!= CompanyId)

       {

           info("test");

           ttsBegin;

           while select crossCompany  eukSecurityTreeNode where eukSecurityTreeNode.EUKMatrixRole == matrixToDuplicate.recId

           {

               changeCompany(_matrix.dataAreaId)

               {

                 select forUpdate  eukSecurityTreeNodeEdit;

                // info(strFmt("company %1",eukSecurityTreeNodeEdit.dataAreaId));

                 try

                 {

                 eukSecurityTreeNodeEdit.data(eukSecurityTreeNode);

                 eukSecurityTreeNodeEdit.EUKMatrixRole =_matrix.recId;

                 eukSecurityTreeNodeEdit.EUKMatrixRoleVersion = _matrix.MatrixRoleVersion;

                 eukSecurityTreeNodeEdit.insert();

              }

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to duplicate table in 2 differents companies?

    You need to debug it.

    What values do you have in

    matrixToDuplicate.dataAreaId and CompanyId when the if condition is checked?

    Should your findByMatrixId method find records from other companies? Are you using crossCompany keyword there?

  • BASMA Profile Picture
    932 on at
    RE: How to duplicate table in 2 differents companies?

    I want t compare the dataAreaId of the matrix to duplicate with the current comapny id.Yes when I choice matrix that have the same areaId as the current company I don't have problem

    FindByMatrixId find values only when the matrix to duplicate has the same areaId as the current company

  • BASMA Profile Picture
    932 on at
    RE: How to duplicate table in 2 differents companies?

    this the function FindByMatrixId :

    public client server static EUKMatrixRole findByMatrixId(

       EUKMatrixNum _matrixID,

       boolean _forUpdate = false)

    {

       EUKMatrixRole eukMatrixRole;

       str CompanyId;

       CompanyId = curExt();

       changeCompany(CompanyId)

       {

           eukMatrixRole.selectForUpdate(_forUpdate);

           if(_matrixID)

          {

           select firstonly  crossCompany eukMatrixRole

           where eukMatrixRole.MatrixID == _matrixID;

          }

           return eukMatrixRole;

        }

    }

    but when I try to create matrix fromather company I get this error :

    "Can not create a record in Tree of an array version (EUKSecurityTreeNode).

    Insertion operations are not allowed between companies. The changecompany password allows you to change the current company before inserting the record."

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to duplicate table in 2 differents companies?

    Does your find method now find records from other companies? So did you make progress and run into a new issue, or are you still in the situation where your execution never goes into the second if statement.

    I think using table.data() to copy the record might not work between companies since it maybe copies the data area id too. Instead of that try toto copy the fields one by one.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: How to duplicate table in 2 differents companies?

    By the way, do you expect this code to do something:

    CompanyId = curExt();

      changeCompany(CompanyId)

      {

    What do you expect it to do?

  • BASMA Profile Picture
    932 on at
    RE: How to duplicate table in 2 differents companies?

    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."

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans