How to figure out errors ViewExceptions .NET API

I'm trying to insert an order using the API - and I'm getting back an error that just says 6666

How can I find what this means, and in general, is there a way to get the COM exceptions and error codes? I know how to get session.Errors, but that is empty in this case.

A I'm trying to do is this. If I remove the RecordCreate, it breaks on setting the CUSTOMER value but it doesn't say why

var view = OpenView("OE0520");

view.RecordClear();
view.RecordCreate(ViewRecordCreate.Insert);

view.Fields.FieldByName("ORDNUMBER").SetValue(order.OrderNumber, false);
view.Fields.FieldByName("CUSTOMER").SetValue(order.CustomerID, true);

  • I have some additional code that might help. I'll dig it out.

    What code do you have for outputting the Sage errors already?

  • in reply to Vega

    I was using Session.Errors but that is empty in this case, other then that just a try/catch. I see they return a code '6666', but there's no reference as to what that means. So, I was wondering if they have the codes listed somewhere

  • In addition to Vega's questions, have you composed your views?  In your example you only show opening OE0520 - there are close to a dozen views necessary to create an order entry order.

    Also - check the customer's credit limit or if they are on hold.  The OE Order Header view will return 'odd numbers' in the error code to relay information back to you.

  • Also search for 6666 on this old page:  https://smist08.wordpress.com/about/

    I think you have something fundamentally wrong with your customization.

  • I use this to catch session errors:

                try
                {
                  // Your code
                }
                catch(SessionException ex)
                {
                    HandleLogRequest($"In {ex.GetType().Name} handler");
                    HandleLogRequest("ex.Reason: " + ex.Reason.ToString());
    
                    if (ex.Data.Count > 0)
                    {
                        foreach (System.Collections.DictionaryEntry de in ex.Data)
                        {
                            HandleLogRequest($"Key: {de.Key.ToString()}      Value: {de.Value}");
                        }
                    }
                    else
                    {
                        HandleLogRequest("ex.Data.Count was 0");
                    }
    
                    HandleLogRequest("ex.GetBaseException(): " + ex.GetBaseException().ToString());
                    HandleLogRequest("ex.HResult: " + ex.HResult.ToString());
                    HandleLogRequest("ex.InnerException: " + ex.InnerException.ToString());
                    HandleLogRequest("ex.Message: " + ex.Message.ToString());
                    HandleLogRequest("ex.Source: " + ex.Source.ToString());
                    HandleLogRequest("ex.StackTrace: " + ex.StackTrace.ToString());
                    HandleLogRequest("ex.TargetSite: " + ex.TargetSite.ToString());
                    HandleLogRequest("WriteSageErrorsToLog(): " + WriteSageErrorsToLog());
    
                    iReturnCode = (int)ExitCodes.CannotLogIntoSage;
                }
                catch (Exception ex)
                {
                    HandleLogRequest($"In {ex.GetType().Name} handler");
    
                    if (ex.Data.Count > 0)
                    {
                        foreach (System.Collections.DictionaryEntry de in ex.Data)
                        {
                            HandleLogRequest($"Key: {de.Key.ToString()}      Value: {de.Value}");
                        }
                    }
                    else
                    {
                        HandleLogRequest("ex.Data.Count was 0");
                    }
    
                    HandleLogRequest("ex.GetBaseException(): " + ex.GetBaseException().ToString());
                    HandleLogRequest("ex.HResult: " + ex.HResult.ToString());
                    HandleLogRequest("ex.InnerException: " + ex.InnerException.ToString());
                    HandleLogRequest("ex.Message: " + ex.Message.ToString());
                    HandleLogRequest("ex.Source: " + ex.Source.ToString());
                    HandleLogRequest("ex.StackTrace: " + ex.StackTrace.ToString());
                    HandleLogRequest("ex.TargetSite: " + ex.TargetSite.ToString());
                    HandleLogRequest("WriteSageErrorsToLog(): " + WriteSageErrorsToLog());
    
                    iReturnCode = (int)ExitCodes.CannotLogIntoSage;
                }
    

    And the method to write out the Sage errors:

            private string WriteSageErrorsToLog()
            {
                if (mbDebugMode) HandleLogRequest($"In {MethodBase.GetCurrentMethod().Name}()");
    
                string sError = "";
    
                if (accpacSession != null)
                {
                    if (accpacSession.Errors != null)
                    {
                        for (int i = 0; i < accpacSession.Errors.Count; i++)
                        {
                            LogHelper.Log(LogTarget.EventLog, $"Sage Error: {accpacSession.Errors[i].Message}");
                            HandleLogRequest($"Error number {i.ToString()}: Sage error code: {accpacSession.Errors[i].Code} - Message: {accpacSession.Errors[i].Message} - Source: {accpacSession.Errors[i].Source}");
                            sError += "\r\n" + accpacSession.Errors[i].Message;
                        }
    
                        accpacSession.Errors.Clear();
                    }
                }
                else
                {
                    HandleLogRequest("No session available");
                }
    
                return sError;
            }
    

    My log helper is a class I wrote that can dump out to a log file, event log, or a database if needed.