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!