NetSuite: Sorting NS_Concat Saved Search Results
case when ns_concat({activity.title}) is not null then '<table border =1>'||REPLACE(ns_concat(distinct '<tr><td>'||{activity.title}||'</td><td>' ||{activity.date}||'</td></tr>'),',','')||'</table>' end
To briefly explain, ns_concat converts an array into a string. So essentially, whatever is inside the ns_concat tags will be looped, until each of the elements in the array have been expressed. Referencing two variables in the same ns_concat will allows us to ensure that the variables correspond to the same activity record.
The function also apparently evaluates HTML tags. Therefore, if you want to loop table rows and table divisions, that is also possible given the above code. Just make sure the main table tag is outside the ns_concat, since that tag shouldn't be looped. The case when function prevents tables from generating if the rows do not have any content (or no activities are related to the opportunity). The case when condition requires the use of ns_concat as well, since the intended output already uses ns_concat.
case when listagg({activity.date}) is not null then '<table border = 1>' || listagg(distinct '<tr><td>'||{activity.date} || '</td><td>' || {activity.title} || '</td>') within group (order by {activity.date} asc) || '</table>' end
We can replace the ns_concat tag with listagg. then after the trailing parenthesis, we can append "within group (order by <variable> asc)". The variable would represent an activity field, so we can sort the table rows based on the results from that field, either in ascending or descending order.
Comments
Post a Comment