Skip to main content

Handle AIF error messages in dynamics AX 2012 R3

Normally, when we consume AIF Service, we use this code like below to handle Error messages

try
{
client.register(ctx, contract);
Console.WriteLine("items registed on Trans Id: " + contract.InventTransId + " with " + contract.Qty + " quantities.");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Ex: {0}", ex.Message));
Console.ReadLine();
}

If it cause error, message would return like this

Handle-AIF-error-messages-in-dynamics-AX-2012-R3

If you want to know more details, you have to go In Dynamics ax AIF Exceptions form then check

Handle-AIF-error-messages-in-dynamics-AX-2012-R3

It's quite hard for 3rd party developer, especially they don't have right to access AX server.

Anyway, we can get meaningful error message by doing below steps

  • Check that box in AIF inbound ports

Handle-AIF-error-messages-in-dynamics-AX-2012-R3

  • Use FaultException class to get message
try
{
client.register(ctx, contract);
Console.WriteLine("items registed on Trans Id: " + contract.InventTransId + " with " + contract.Qty + " quantities.");
Console.ReadLine();

}
catch (System.ServiceModel.FaultException<ItemsRegistration.RegRef.AifFault> aifFault)
{
//FaultMessageList[] list = aifFault.Detail.FaultMessageListArray[0];
InfologMessage[] list = aifFault.Detail.InfologMessageList;

foreach (InfologMessage message in list)
{
Console.WriteLine(message.Message);

}
Console.ReadLine();

}

what we got

Handle-AIF-error-messages-in-dynamics-AX-2012-R3

Thank you for reading.