Page 1 of 1

Checkgroup not showing as checked in output Doc

Posted: Mon Mar 13, 2017 3:30 am
by springhigh
Hi
I am trying to display a checkgroup in an output document.
I have tried all the forum solutions, and can't get it working.
The output doc does not show the checkboxes (checked or unchecked) in work or pdf

Would be gratefull if someone has a working example they could upload ?

this is the example i am currently testing (PM 3.1)

Checkgroup Dynaform Variable = CurrentOutpatientTreatmentOrder
Key = 1 Label = MarkOrder1
Key = 2 Label = MarkOrder2
Key = 3 Label = MarkOrder3

Output Doc HTML
Code: Select all
<form>
<input  type="checkbox" value="1" @#MarkOrder1> Option 1<br>
<input  type="checkbox" value="2" @#MarkOrder2> Option 2<br>
<input  type="checkbox" value="3" @#MarkOrder3> Option 3<br>
</form>
Trigger befor Output Doc
Code: Select all
$aSelected = explode('|', @@CurrentOutpatientTreatmentOrder);     
if (in_array("1", $aSelected)) //asumiendo que 1 es el valor de una opción en el checkgroup
     @@MarkOrder1 = "checked";
else
     @@MarkOrder1 = "";

if (in_array("2", $aSelected)) 
     @@MarkOrder2 = "checked";
else
     @@MarkOrder2 = "";

if (in_array("3", $aSelected)) 
     @@MarkOrder3 = "checked";
else
     @@MarkOrder3 = "";

Re: Checkgroup not showing as checked in output Doc

Posted: Mon Mar 13, 2017 5:15 pm
by amosbatto
What version of PM are you using? Your code will work in classic processes originally created before PM 2.5. The HTML editor introduced in PM 2.5 screws up the HTML code, so this:
Code: Select all
<input  type="checkbox" value="1" @#MarkOrder1> Option 1<br>
becomes:
Code: Select all
<input  type="checkbox" value="1" MarkOrder1="MarkOrder1"> Option 1<br>
The solution is to place all the HTML code in a case variable and insert that case variable in the template for the Output Document.

If you have a BPMN process in PM 3, then the selected options in checkgroups are stored as an array (not a string separated by '|' like in classic processes), so you have to access them differently in the trigger.

First, create a checkgroup like this in your DynaForm:
servicesCheckgroupInDesigner.png
servicesCheckgroupInDesigner.png (16.19 KiB) Viewed 1349 times
with the following list of options:
CheckgroupInOutputDoc.png
CheckgroupInOutputDoc.png (9.9 KiB) Viewed 1349 times
The HTML code for your Output Document template should look like this:
Code: Select all
<form>
<p>Services Required:<br />
@#servicesHtml</p>
</form>
Then, create a trigger to set the value of the @@servicesHtml case variable which is used in your template, like this:
Code: Select all
$formId ='81710538658c6bff6a3e8a7056075051'; //set to ID of DynaForm
$fieldId = "servicesRequired"; //set to ID of checkbox group

$aFields = PMFDynaFormFields($formId, @@APPLICATION, @%INDEX);
@@servicesHtml = '';

foreach ($aFields as $aField) {
	if ($aField->id == $fieldId) {
		foreach($aField->options as $aOpt) {
			$checked = '';
			if (isset($aField->value) and is_array($aField->value) and 
				in_array($aOpt->value, $aField->value)) {
				$checked = 'checked="checked"';
			}
			
			$val = $aOpt->value;
			$label = $aOpt->label;
			@@servicesHtml .= "<input type=\"checkbox\" value=\"$val\" $checked>$label\n";
		}
	}
}
Set this trigger to fire before the Output Document step in your process.

This trigger uses the PMFDynaFormFields() function to get the list of options in the checkgroup. It places the value and label for each option in the HTML code for a checkbox and appends that code to the @@servicesHtml case variable which is used in the Output Document template.

When a case is run it will generate an Output Document file with the following checkgroup embedded in the document:
CheckgroupOptions.png
CheckgroupOptions.png (9.18 KiB) Viewed 1349 times
To try out this example, download and import the
(27.73 KiB) Downloaded 197 times
process.

The one drawback of this approach is that it doesn't work with a checkgroup whose list of options is dynamically generated from a variable or an SQL query. For a dynamically generated list of options, the only solution is to add JavaScript to the DynaForm which saves the list of options when the DynaForm is submitted as a JSON string in a hidden control. Then decode this JSON string instead of using the PMFDynaFormFields() function to get the list of options.

Re: Checkgroup not showing as checked in output Doc

Posted: Tue Mar 14, 2017 2:14 am
by springhigh
Thanks amosbatto , I'm using PM3
Have tested and it works 100% on PDF , but Word won't display the Checkbox at all on my Mac.
It seems like it may be my version of word, or my word installation, as it works in word on other PC systems.
I'm using word for Mac, Version 15 (latest)

Re: Checkgroup not showing as checked in output Doc

Posted: Fri Oct 11, 2019 4:45 am
by Zora99
Can it just show the checked item and hide the unchecked item?