No items found.

Renaming primary key in AX 2012

User perspective

To change primary key in Dynamics AX 2012 you need to select record, right click on it and select Record info. In Record information form click Rename button, write new ID and click OK. System will ask if you are sure to rename from old to new ID – click Yes. After that system will try to change that key and if there will be no issues it will do it.

changing primary key in Dynamics AX 2012

Developer perspective

To include table in automated key change it needs to be directly related. This means it has to have:

Relations

  1. In AOT on table in Relations node needs to be added relation to master table on primary key.
  2. Relation must have property Validate set to Yes.

EDT

  1. EDT used needs to have relation or reference to primary key on master table.
  2. Table must use the same or extended EDT like primary key in master table.
  3. Field need to have property IgnoreEDTRelation set to No.

To include additional not directly related table you need to overwrite renamePrimaryKey method. Below is example code for that in ProjTable – to make it shorter I removed standard code from that method:

server void renamePrimaryKey(boolean psaIncluedeSubProjects = true)

{

   ProjTable               originalRecord;

   VendInvoiceInfoLine_Project                 vendInvoiceInfoLine_Project_group;

   VendInvoiceInfoLine_Project                 vendInvoiceInfoLine_Project;

   ttsBegin;

   originalRecord = this.orig();

   while select crossCompany vendInvoiceInfoLine_Project_group

           group by DataAreaId

           where   vendInvoiceInfoLine_Project_group.ProjDataAreaId    == this.dataAreaId

               &&  vendInvoiceInfoLine_Project_group.ProjId            == originalRecord.ProjId

   {

       changeCompany(vendInvoiceInfoLine_Project_group.dataAreaId)

       {

           update_recordSet vendInvoiceInfoLine_Project

                   setting ProjId = this.ProjId

                   where  vendInvoiceInfoLine_Project_group.ProjDataAreaId    == this.dataAreaId

                       && vendInvoiceInfoLine_Project_group.ProjId            == originalRecord.ProjId;

       }

   }

   super();

   DimensionStorage::syncRenamedValue(this, originalRecord);

   ttsCommit;

}

If the specific table is used in dimensions then it is really important to also update them. We can do this calling method DimensionStorage::syncRenamedValue(this, originalRecord).

Zobacz inne

OneLake: czyli jak uporządkować odwieczny chaos w danych

Czytaj artykuł
Text Link

Ręczne przetwarzanie zamówień sprzedażowych to strata czasu. Jak to zautomatyzować?

Czytaj artykuł
Text Link

Najlepszy system ERP na 2026 rok? Microsoft Dynamics 365 w rankingach Gartner Magic Quadrant

Czytaj artykuł
Text Link
Wróć do wszystkich

Porozmawiajmy o Twoim projekcie

Napisz, z czym przychodzisz: wdrożenie, migracja, rozwój systemu albo pytanie, na które szukasz odpowiedzi. Wracamy z konkretną propozycją następnego kroku, nie z prezentacją handlową.

Dziękujemy za wiadomość!
Oops! Something went wrong while submitting the form.
Microsoft AI Builder
Microsoft Copilot Studio
No items found.
No items found.
No items found.