Skip to content


Tech Tuesday : Write Back Error Message

 While doing an integration into Dynamics GP, have you ever wanted to be able to write back the error message returned by Dynamics GP to the source system? However, the error message is “too confusing”, so you would rather just show the error description to make it easier to read. For example, here is the error message that is returned from Dynamics GP eConnect for creating a new Vendor that already exists.

You would rather just send this text back to the source system to track the error description.

To do this, you would need to create a new global variable, called GBL_LAST_ERROR.

Then you would create a task to run a script on document failure. SmartConnect stores the last error in a global variable called GlobalLastError. We use that error, and search for the string between “Error Description” and “Node Identifier”. This gets you the error description you are looking for.

Here is the code if you want to include the error number, stored procedure name, and the error description:

Dim LastError as String
Dim ErrorNumberLocation as Integer
Dim NodeIdentifierLocation as Integer
Dim NewLastError as String
LastError = GlobalLastError
ErrorNumberLocation = LastError.IndexOf(“Error Description”)
NodeIdentifierLocation =  LastError.IndexOf(“Node Identifier”)
if ErrorNumberLocation > -1 and NodeIdentifierLocation > -1
NewLastError = LastError.Substring(ErrorNumberLocation, NodeIdentifierLocation  – ErrorNumberLocation  – 2)
NewLastError = “Vendor Create Failed”
end if
return true


Now that you have the global variable “GBL_LAST_ERROR” value set. You can then pass that global variable to a 2nd map that updates the source data by sending the global variable to the error description location in the source data.


Happy Coding!


  1. Alex on March 10, 2020 at 10:32 am

    What does the last part mean? Can you explain the last step better/in more detail?
    Here it is;
    ” Now that you have the global variable “GBL_LAST_ERROR” value set. You can then pass that global variable to a 2nd map that updates the source data by sending the global variable to the error description location in the source data. ”

    Can you explain how you would pass the GBL_LAST_ERROR to a 2nd map?
    How it updates the source data?
    How you would create the 2nd map and steps to write the error message on the source data?

    I want to have the errors listed on the “fix” tab, so i can sort it / hide the duplicate invoice number error.

    Thank you!!

  2. Chad Bruels on March 23, 2021 at 12:10 pm

    On the Document Failure task your GlobalLastError variable contains the error from the previous document instead of the current document that failed. I need a solution for getting the error of the current document that just failed.

    • Glenn Lasowski on December 1, 2021 at 4:10 pm

      I’m having the same issue.

  3. Don Tricker on September 21, 2021 at 7:31 am

    Hi, is it possible to manually throw an error with an error description in a pre-document script. The idea is to pre-validate some data, and fail the document with a specific error message?

  4. Patrick Roth on September 23, 2021 at 4:17 pm

    Yes – certainly.

    In your script, just throw an exception:

    throw new System.Exception(“Here is my error!”)

    Obviously you can put whatever you want in the error – I would assume details of the error and probably information on how to find the “problem” data such as your key field or some other way to see which record is the one that failed.

    Why this works is that SC catches the exception and then just logs it like any other error.

Leave a Comment


Accessing Your Historical Dynamics NAV Data in D365 Business Central - Part 1: Getting Started
eOne Welcomes Incremental Group as a New eOne iPaaS Integration Partner
Employee Spotlight: Floyd Jones, Front End Developer
NEW WEBINAR: Popdock Onboarding - Fall in Love with Your Data
Employee Spotlight: Calum McGrath, Implementation Consultant


2016 SmartConnect Integration Bootcamps
Tech Tues: Automatically refreshing Pivot Tables in Excel Refreshable Reports
Happy Thanksgiving from the eOne team!
2017 SmartConnect Integration Bootcamps
New Releases of Extender and SmartList Builder



Business Central CRM D365 Business Central Dynamics 365 dynamics crm Dynamics GP Dynamics NAV Econnect Employee Spotlight eone eOne News error Error Message Events Excel Excel Report Builder Extender Flexicoder GP integration Map Meet the Team Microsoft dynamics crm Microsoft Dynamics GP Navigation List Builder Office Relationships Partner All Hands Call Popdock promotions release SalesForce SmartConnect SmartConnect Bootcamp SmartConnect Maps SmartConnect Office Hours SmartList SmartList Builder SmartPost SmartView SQL Tech Tuesday Templates training

Integrate & Automate without Any Code.

SmartList Data has Never Been Faster.

The Easiest Way to Report on GP Data.