If you want to get all the error messages in the infolog in a desired language then just put this small code snippet and run it in a job.
infolog.language(LanguageId);
then whole UI of AX Client will be changed to the desired language and we will get the error messages into the infolog in that language only.
Now, when you are communicating an external application with AX and the language id of the login user of AX is different from the desired language, if you want to catch the error messages in any of your methods then the code snippet is as follows:
In the try catch block, put the following code into catch and thus you can get all error messages into a string and return it to an external application in the desired language.
Str infoLogInfo, infologErrorMsg, errorMsg;
Container holdError;
LanguageId languageId, defaultLanguageId;
//Desired Language Id
languageId = ‘de’;
//Default user Language Id
DefaultLanguageId = languagetable::defaultLanguage();
//Input the desired language id to infolog
infolog.language(LanguageId);
//collect the error messages from infolog in the desired language into a container
HoldError = infolog.infologData();
for(i=2;i<=conlen(HoldError);i++)
{
[InfoLogInfo,InfologErrorMsg]= conpeek(HoldError,i);
ErrorMsg = ErrorMsg +’||’+ InfologErrorMsg;
}
//Change back to the original language
infolog.language(DefaultLanguageId);
//return the error messages in the desired language
return ErrorMsg;