This article is relevant if you would like to work with NetSuite’s NS_CONCAT aggregate function and turn the results into hyperlinks and URLs.
Background
Back in 2014, I wrote an article, Reveal Both Aggregate and Detail in NetSuite Saved Search, which helped to describe a NetSuite function that allows you to get at detail information in an aggregated / summary search. Given NetSuite’s hierarchical database nature, the opportunity for information that is summarized at one level but the need to reveal elements of the underlying summary (the detail) is highly probable.
While I thought the NS_CONCAT function was novel, it wasn’t that useful in that is just revealed a comma-separated list of values. Since writing that article 6 years ago, I always had it in the back of my mind that I could make it better.
Transforming NetSuite NS_CONCAT for Hyperlinked Information
In my mind, if I was going to use an aggregate search that can reveal elements of the detail, I thought that a hyperlink to that detail was the best use case. To solve this, I set up a simple scenario.
- Vendor Bills: many of the consultants on our team are outside contractors and thus we pay them via vendor bills.
- Payments: we pay our team every two weeks.
In this simple scenario, we will aggregate the vendor bills and group by payments. We want to reveal a hyperlink to each of the vendor bills yet summarize at the payment level.
Two elements of information are needed in the hyperlink:
- Internal ID: we need the internal ID of the vendor bill (transaction).
- Descriptions: we need the hyperlink description; in this case, we will reveal the vendor bill document number.
Build a Custom Delimited NS_CONCAT Data Set
Thus, the first step was to come up with a way to get the needed information in the NS_CONCAT function and build a delimited set of data that can be later parsed apart. Here is the function that I came up with:
NS_CONCAT('(' || {appliedtotransaction.number} || '{*}' || {appliedtotransaction.internalid} || ')')
In this scenario, I am using ‘{*}’ to represent a delimiter between the two categories of data: the vendor bill number and the internal ID. I also decided to play safe and delimit the detail data results with parenthesis so that I could more easily isolate out the comma that NetSuite will produce automatically. Click to see the related image.
Build a Regular Expression to Parse the Custom Delimited NS_CONCAT Data Set
Next, using regular expressions, we can build a parser. I originally tried to work with NetSuite’s underlying Oracle engine to use PL/SQL based REGEX. However, it appears that it would not support the replacement elements I needed with REGEX groups for the work I needed to transform the results into hyperlinks. Thus, I decided I would stay in the JavaScript world and parse in the browser the output.
This is the regular expression that would break the output into two parts using groups: the document name and the internal ID.
/\(([^,]+)\{\*\}(\d+)\),*/g
Generate the Output Into a Script
Once I had the regular expression, I was then able to use a simple JavaScript function to replace the parsed information into a hyperlink. This then became the formula in my aggregate search. Click the related image to see more.
'<script> var r = /\(([^,]+)\{\*\}(\d+)\),*/g; var s = ''' || NS_CONCAT('(' || {appliedtotransaction.number} || '{*}' || {appliedtotransaction.internalid} || ')') || '''; var h = ''<a class="dottedlink" target=_blank href="/app/accounting/transactions/transaction.nl?id=$2">$1</a><br />''; var o = s.replace(r, h); document.write(o); </script>'
Demand More from your NetSuite Investment
While I suspect there are other approaches to producing similar results using NS_CONCAT, I can now let that gnawing “what if” puzzle rest knowing that it is indeed solved. This is yet another example of why I love the NetSuite platform. We can all leverage the built-in capacities which give us so much to start with when solving business problems — and then we can go the extra length to produce meaningful enhancements without the old school need to run a complex and expensive information technology project.
If you found this article meaningful, feel free to subscribe to be notified of new articles as I post them. If you would like to work with expert individuals in NetSuite, accounting, and technology, let’s have a conversation.
Following error is thrown:
ERROR: Results cannot display script output for security reasons.
Hello Mitisha,
Looks like NetSuite has produced a new locked down on JavaScript security in the output of Saved Searches. I will need to find a workaround.
Marty
Just messing around this seems to work fine for hyperlink in a NS_CONCAT. I am linking to the SO and the text to show is document Number and PO#. I am using minimum as the summary type:
replace(ns_concat(distinct ‘‘ || {number} || ‘ – ‘ || {otherrefnum} || ‘‘),’,’,”)
Let me know if I am missing the point here…
Best,Jacob
On my last comment the HTML tags parsed into a link instead of showing the source code for the formula.
This is the Actual Formula <! replace(ns_concat(distinct '‘ || {number} || ‘ – ‘ || {otherrefnum} || ‘‘),’,’,”) >
Hello Jacob,
This looks like another good application of NS_CONCAT. Thank you.
Marty