Wednesday 21 October 2015

AX 2012 Label ids are being displayed in Security roles form instead of text?

Hi,
I recently faced this issue where labels were appearing in the security roles form.
And surprisingly, those labels existed in AX.

To investigate further, I opened up my SecurityRole table and found out that AX had got Label ids in the Name and Description column instead of actual text. To fix this, I simply ran an X++ job that updated the table.

static void updateSecurityTableLabels(Args _args)
{
   SecurityRole role;
   SecurityTask task;
   LanguageId LanguageId = CompanyInfo::find().LanguageId;
   LanguageId fallBackLanguageId = "en-us";
   str newLabelStr;
   #define.LabelPrefix('@DMF*')
   ttsBegin;
   while select forUpdate role
   {
       if(role.Description like #LabelPrefix)
       {
           newLabelStr = new Label(LanguageId).extractString(role.Description);
           if(newLabelStr like #LabelPrefix)
           {
               newLabelStr = new Label(fallBackLanguageId).extractString(role.Description);
           }
           role.Description = newLabelStr;
           role.doUpdate();
       }
       if(role.name like #LabelPrefix)
       {
           newLabelStr = new Label(LanguageId).extractString(role.name);
           if(newLabelStr like #LabelPrefix)
           {
               newLabelStr = new Label(fallBackLanguageId).extractString(role.name);
           }
           role.name = newLabelStr;
           role.doUpdate();
       }
   }
   ttsCommit;
   info("Done");
}