Tech Tuesday: Integrating Record Notes in Dynamics GP with SmartConnect
Notes! Who doesn’t love record level notes in Dynamics GP? What’s not to love about having a freeform text field to enter 32k of information into?
Long time GP users know that the (almost) universal field for a note is the NOTEINDX field in the table for that GP record. For a RM Sales Transaction, the RM10301 table. The actual notes themselves in the “core” GP dictionary are stored in the SY03900 table using that same NOTEINDX field to link the two records together.
What isn’t so well known is that the “Note Text” for most destination types isn’t available in eConnect. Fortunately, some of the populate destinations such as Customer/Vendors and POP/SOP in eConnect DO have a “Note Text” available to create the record notes for those items. However outside of that, there are probably only a few other destinations that support this functionality.
So, what is a SmartConnect user to do if their GP destination doesn’t support this but we really want to integrate that note?
The common practice in SmartConnect to do “other stuff not supported by the destination” is to use an “After Document Success” task. Sometimes this is to update the source data to provide information about the success/fail of a record from a source SQL table. Or in our case, we are going to directly adjust data in the target SY03900 table.
To start off, we’ll create some simple data for two RM Transaction Invoices in Excel.
We added a “Note” column and some data for each note. I also highlight another challenge we’re going to run into with the note on the transaction for ADAMPARK0001 as there is a single quote in the message. For those with a bit of SQL experience, they know that single quotes must be “escaped” in order to be inserted into the SQL table. In order to handle that, we’ll need a trick in our coding.
I won’t post all the details for the RM Trx since there isn’t anything special about creating the test RM Invoices, but I will note the GP Rolling Column that we are using for the “next document number” for our invoices.
Dynamics GP creates a NOTEINDX value for every record created whether there is an actual note created at that time. Because we’re getting that “next number” on the fly, we need to mark this checkbox so that we can get the value that SmartConnect is using for that document.
After doing the mapping, we create the two global variables GBL_DOCNUMBER & GBL_NOTE that the script is going to use. Refer to the SmartConnect Documentation on global variables if necessary.
Next, create a new “After Document Success” script task. I called mine SET_GLOBALS.
Here is where I put in the “trick” that I said we’d need because of the single quote in “Jack O’ Lantern”.
I might have been tempted to just use the Replace() in my SQL script and not use a second script task– but that actually would fail. The reason is that SmartConnect replaces the field tokens directly so that means Replace(‘_NOTE’) in the SQL Script would be replaced with Replace(‘Jack O’ Lantern’) which would also be unbalanced and fail. So we do the Replace() in the .NET script instead.
Also notice that I used the VB “Chr” function instead of just using the single quote. The reason is that it is hard to see “’” in a screenshot or replace with “’’” and figuring out what characters are what. But you can do it either way.
GBL_DOCNUMBER = GlobalRollingColumn
GBL_NOTE = _NOTE.Replace(Microsoft.VisualBasic.Chr(39),
Microsoft.VisualBasic.Chr(39) + Microsoft.VisualBasic.Chr(39)))
char singleQuote = (char)39;
GBL_DOCNUMBER = GlobalRollingColumn;
GBL_NOTE = _NOTE.Replace(singleQuote.ToString(), singleQuote.ToString() + singleQuote.ToString());
And then the SQL Task that will come after the script task above.
Because it isn’t possible that we can update an existing RM Trx Invoice with eConnect, I don’t have to check for an existing record note using exists() in the query above. However, since we can re-use this node code above with any eConnect destination (by just adjusting the select @noteindex query and where clause to the correct table) I thought I’d add it here.
select @noteindex = NOTEINDX from RM10301 where RMDTYPAL = 1 and
DOCNUMBR = ‘GBL_DOCNUMBER’
if @noteindex > 0
if exists(select 1 from SY03900 where NOTEINDX = @noteindex)
update SY03900 set TXTFIELD = ‘GBL_NOTE’ where NOTEINDX = @noteindex
insert SY03900 (NOTEINDX,DATE1,TIME1, TXTFIELD) values
(@noteindex,CONVERT(VARCHAR(10), GETDATE(), 101),
CONVERT(VARCHAR(12), GETDATE(), 108) ,’GBL_NOTE’)
Crossing my fingers that we don’t have a typo or logic mistake, I run the integration which says it was successful. But were the notes – especially the Jack ‘O Lantern one – ok?
Checking the second document created, we look at the note and it looks like success!
What we learned in this article:
- How to use ‘after document success’ tasks in order to update “other” data that doesn’t have a built-in destination using a SQL Task.
- How to use a .NET Script Task and a SmartConnect Global Variable in order to fix issues with single quotes in source/destination data in a SQL Task.
- Marking the “Use for Global variable” checkbox on the GP Rolling Column in order to use the GlobalRollingColumn variable in script.
You can download the map and source file HERE.
Leave a Comment
Integrate & Automate without Any Code.
SmartList Data has Never Been Faster.
The Easiest Way to Report on GP Data.
Hi! Do you know how to integrate attachments with Transactions? E.g. I have PDF files that are required to be upload to GP with the creation of a corresponding Payables transaction record. I have got the metadata for the transaction and PDF blobs in SQL Server database. Any idea would be greatly appreciated.
Out of the box, there isn’t an eConnect node that does GP document attachments.
However our services team has created such a node for SmartConnect/eConnect that does this.
The above blog post gives contact information to the services team if you want to inquire what that involves.