Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to duplicate table in 2 differents companies?

Posted on by 920

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

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

    I'm not sure I understand what you are asking.

    If you want to select data across companies you have to use the crosscompany keyword.

    If your data in table A is referencing to table B, you have to copy the record of both tables in the other company. Table relations can't see into other companies.

    Does this answer your question?

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

    Hi Nikolaos Mäenpää,

    When I copy fields I don't get error but that table depends on others tables (EUKSecurityForm,EUKSecurityMenuItems,EUKSecurityMenus)like this :

    eukSecurityTreeNode.EUKSecurityForm=EUKSecurityForm.recId;

    eukSecurityTreeNode.EUKSecurityMenuItems=EUKSecurityMenuItems.recId;

    eukSecurityTreeNode.EUKSecurityMenus=EUKSecurityMenus.recId;

    I should do selection statement from the other tables using "CrossCompany"??

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

    Hi,Thanks for your help.

    Now when I copy fields one by one I don't get error .

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

    I already suggested to not use table.data() since it is most likely causing your issue. But you still have it in your code.

    By the way this code which I asked you about doesn't do anything:

    CompanyId = curExt();

     changeCompany(CompanyId)

     {

    First you take the current company. Then you change company scope to current company. So nothing changes. The company scope was already the current one!

  • BASMA Profile Picture
    BASMA 920 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."

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 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?

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 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.

  • BASMA Profile Picture
    BASMA 920 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."

  • BASMA Profile Picture
    BASMA 920 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

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 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?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans