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)
else
NewLastError = “Vendor Create Failed”
end if
GBL_LAST_ERROR = NewLastError
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!
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!!
Alex
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.
I’m having the same issue.
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?
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.