0

using openTBS (in the SugarCRM plugin MailMergeReports) and I have the following in my Word template.

[a_sub5;block=w:p;nodata] No States
[a_sub5;block=w:p][a_sub5.name]

This works fine as far as it goes - it outputs a single state name per line - which is fine when the data only has a few states.

The problem is I want it to output the list of states as a comma separated string rather than 1 state per line. I have tried multiple options with no luck! Is this not possible to do? or am I just missing the obvious syntax needed to accomplish it.

Note: because I am using TB via a 3rd party plugin to SugarCRM CE I do not have ready access to the PHP code. I need a solution that can be accomplished just within the template specification.

bcaverly
  • 11
  • 2

1 Answers1

0

If you had no the nodata section, you could try with [a_sub5.nom;block=!w:r], but this would add an extra coma at the end of the list. This doesn’t work since you have the nodata section because the 2 TBS sections are not continuous, thus it will produce an invalid XML.

My advice is to format your list at the TBS side, then merge it into the template :

PHP :

$list = array_column($data, 'name');
$list = implode(', ', $list);
if ($list == '') $list = "No States";
TBS->MergeField('a_sub5', $list);

Template:

[a_sub5]

If is a sub-block, then you can use a onformat custom function for making the list.

Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • The recommendation of `implode(array_column())` has been given over a hundred times on Stack Overflow. If this was the resolving advice, then please close this page with with https://stackoverflow.com/questions/4705814/create-a-comma-separated-string-from-a-single-column-of-an-array-of-objects (the earliest reference that I have found). Truth is, the asker says that they are seeking a non-PHP solution. – mickmackusa Jul 27 '22 at 22:58