web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Getting Warning/Error message from aif exception table

(0) ShareShare
ReportReport
Posted on by 59

I have an external application that writes to the general journal. When an error occurs its just has a basic description "error validating record" for example. I would also like to return the warning message as it is more detailed. Problem is i don't know how to catch the warning message in code and return it with the error back to my 3rd party app. So i ended up catching the error and then querying the sys exception table. But the issue seems to be a delay now. Which means it doesn't write the error/warning to the table until the aif service is completely out. So it will always return the last error instead of the current error. See code below. IF there is a better solution to get the warning returned let me know. i have looked around and nothing seemed to work.

catch (Exception::Error)
              {
select maxOf(createdDateTime) from sysExceptionTable where sysExceptionTable.Exception==Exception::Warning && (sysExceptionTable.createdBy=='username' || sysExceptionTable.createdBy=='username');
                  select description from sysExceptionTable2 where sysExceptionTable2.Exception==Exception::Error && (sysExceptionTable2.createdBy=='username' || sysExceptionTable2.createdBy=='username') && sysExceptionTable2.CreatedDateTime==sysExceptionTable.createdDateTime;
                  errorMsg=sysExceptionTable2.Description;

                  select description from sysExceptionTable2 where sysExceptionTable2.Exception==Exception::Warning && (sysExceptionTable2.createdBy=='username' || sysExceptionTable2.createdBy=='username') && sysExceptionTable2.CreatedDateTime==sysExceptionTable.createdDateTime;

                  errorMsg=errorMsg + " " + sysExceptionTable2.Description;


                 throw Global::error(errorMsg);
         }



*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Getting Warning/Error message from aif exception table

    typical AIFs are made through the wizard and use table level errors and only returns the top error / warning (not the entire infolog) which mimics the behavior you're explaining.

    You could have a try / catch in that method, and return it as errorMsg on the method call.  Hopefully that makes sense.

    I ended up rewriting those AIFs so I could catch all the messages and return them as a string.

  • Sirus49 Profile Picture
    59 on at
    RE: Getting Warning/Error message from aif exception table

    sorry i don't understand what your resolution is

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Getting Warning/Error message from aif exception table

    the method call (from your external application), go to that method inside the AOT in AX.

    wrap the code there (in AX) with a try catch and put that error into a string, then return that string.

    That might make you change your return type on that method btw.  

  • Sirus49 Profile Picture
    59 on at
    RE: Getting Warning/Error message from aif exception table

    Yes i am already doing that. and yes i can return that error message. But i want the warning message because theres more detail then the error message. thats why i tried to get it from the exception table because it lists error plus warning

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Getting Warning/Error message from aif exception table

    ah, I understand a little more. sorry.

    I would suggest removing catch(Exception::Error) and replace it with a blank catch and put the following code:

                   try

                   {

                       your.code.here();

                   }

                   catch

                   {

                       errorMessage = this.getInfoLog();

                       resultSet.addEnd(strFmt(errorMessage));  // returning this at the end.  resultSet is a List of type string

                       infolog.clear();

                       throw Exception::Error;

                   }

    where this.getInfoLog() is below:

    private str getInfolog()

    {

       int                 j;

       int                 lastline;

       str                 rtnval;

       lastline = infologline();

       for (j = 1;j <= lastline;j++)

       {

           rtnval += ' '+ infolog.text(j);

       }

       rtnval = strReplace(rtnval,'\t',',');

       return rtnval;

    }

    That'll get the entire infolog.

  • Sirus49 Profile Picture
    59 on at
    RE: Getting Warning/Error message from aif exception table

    ok, so when exception::error gets thrown back to my 3rd party app. This is actually where i need to capture the contents of resultset.

  • Community Member Profile Picture
    on at
    RE: Getting Warning/Error message from aif exception table

    correct.

  • Sirus49 Profile Picture
    59 on at
    RE: Getting Warning/Error message from aif exception table

    I actually found another solution on the .net side capturing the aiffault

    Catch except As System.ServiceModel.FaultException(Of GeneralJournal.AifFault)

               For Each exceptionLog In except.Detail.InfologMessageList

                   ErrorMessage = exceptionLog.Message.ToString + vbNewLine + ErrorMessage

               Next

               Throw New FaultException(ErrorMessage.Trim)

  • Community Member Profile Picture
    on at
    RE: Getting Warning/Error message from aif exception table

    I prefer this approach as well.  We do the same in our client code where we catch an AifFault of whichever specific type we happen to be using (e.g., AxdSalesOrder) and then use the InfologMessageList to fill a domain-specific exception that we can use with other non-AX objects throughout the enterprise environment.  This obviously only works, however, when the AIF service is configured to provide detailed exception information.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#1
Community Member Profile Picture

Community Member 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans