Page 1 of 1

Array in Output Document

Posted: Wed Oct 24, 2018 6:47 am
by fibo2358
Hello,

I would like to put a table in an Output Document which is populated from the Array variable.
I have found a section in the documentation regarding the grids in the Output Documents:
https://wiki.processmaker.com/3.2/Outpu ... _documents

However, I cannot find any information about arrays.
Please help.

Best Regards,
fibo2358

Re: Array in Output Document

Posted: Wed Oct 24, 2018 11:00 am
by andreaadamczyk
Hello,

You can create an array type variable, and in a trigger before the output document, set the value of that variable with the array.

Then, in the HTML editor of the output document you can use this code to create the document:
Code: Select all
<table width="100%" border="1">
<!--@>GRID-VARIABLE-NAME-->
<tr>
<td width="25%">@#Field1</td>
<td width="25%">@#Field2</td>
<td width="25%">@#Field3</td>
<td width="25%">@#Field4</td>
</tr>
<!--@<GRID-VARIABLE-NAME-->
</table>
Where the "GRID-VARIABLE-NAME" is the name of the array variable you created before, and the "Field-X" are the fields of the array.

I hope this information would help you.

Please, let me know how it goes.

Regards.

Re: Array in Output Document

Posted: Thu Oct 25, 2018 3:34 am
by fibo2358
Hello ,

Thank you very much, that worked fine.
I guess that the documentation should be updated, it is not obvious that the solution used in grids may be applied to the arrays.
I will enter a separate post for this update.

Best Regards,
fibo2358

Re: Array in Output Document

Posted: Thu Apr 18, 2019 8:23 am
by HeshanKaru1994
Can you show a sample code in use with more details as i'm new to processmaker

Re: Array in Output Document

Posted: Thu Apr 18, 2019 3:25 pm
by amosbatto
HeshanKaru1994 wrote:Can you show a sample code in use with more details as i'm new to processmaker
Where you unable to follow this example?

Are you editing the HTML code in your template? (Look for the "HTML" button in the template editor.)
Are you matching the exact spelling for your Grid variable and the IDs of the fields inside the grid?

If you still can't figure it out, then post your process and indicate which dynaform has the grid and which Output Document should have the inserted grid.

Re: Array in Output Document

Posted: Fri Apr 19, 2019 5:49 am
by HeshanKaru1994
Inside a trigger I am generating array of items(without using grids) and I want that array to be shown inside a html table in a template document

Re: Array in Output Document

Posted: Mon Apr 22, 2019 9:37 pm
by amosbatto
HeshanKaru1994 wrote: Fri Apr 19, 2019 5:49 am Inside a trigger I am generating array of items(without using grids) and I want that array to be shown inside a html table in a template document
You can use trigger code like this to create an array that looks like a grid to ProcessMaker:
Code: Select all
@=myGrid = array(
  1 => array( 'field1' => 'row1value1', 'field2' => 'row1value2', 'field3' => 'row1value3'),
  2 => array( 'field1' => 'row2value1', 'field2' => 'row2value2', 'field3' => 'row2value3'),
  3 => array( 'field1' => 'row3value1', 'field2' => 'row3value2', 'field3' => 'row3value3')
);

Then use this in the HTML code of your template file:
Code: Select all
<table width="100%" border="1">
<tr><th>My Field 1</th><th>My Field 2</th><th>My Field 3</th></tr>
<!-- @>myGrid -->
<tr>
<td width="32%">@#field1</td>
<td width="32%">@#field2</td>
<td width="32%">@#field3</td>
</tr>
<!-- @<myGrid -->
</table>

Re: Array in Output Document

Posted: Fri Jun 07, 2019 3:31 am
by HeshanKaru1994
Hi my trigger to create array:
Code: Select all
$aKeys = array_keys(@=result);
@=key = array();
for($x=0; $x < $count;$x++){
	@=key[] = $aKeys[$x];	
}
the result of the trigger

Array ( [0] => Array One [1] => Array Two )

How to map this situation to the output table

Re: Array in Output Document

Posted: Fri Jun 07, 2019 8:42 pm
by amosbatto
If @=result has the structure of a grid variable, then you can include it in the template of your Output Document like a normal grid.

If @=result doesn't have the structure of a normal grid variable, then you will have to create the HTML code for a table and then place that HTML in a case variable which you put in the template of your Output Document.

Can you post the content of your @=result variable? It is hard for me to give you a code example for how to output it as an HTML table without knowing the structure.

For example, if @=result contains:
Code: Select all
[   
    'Expenses' => 2435.48,
    'Revenue' => 5699.50,
    'Income'   => 2300.55
];
Then, you can use the following trigger:
Code: Select all
@@tableContent = "<table>\n";

foreach (@=result as $key => $val) {  
        @@tableContent .= "<tr><td>$key</td><td>$val</td></tr>\n";
}
@@tableContent .= "</table>";

Then, place @#tableContent in your Output Document template.

Re: Array in Output Document

Posted: Fri Jun 07, 2019 9:14 pm
by HeshanKaru1994
Thank you works fine

Re: Array in Output Document

Posted: Mon May 11, 2020 6:36 pm
by DannyShimmer1
Thank you for sharing this. It helped me a lot.