Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#813485
Hi,

Is there a custom script or trigger that makes it easy for users to generate output document with a default template. For instance, each dynaform control already has an ID on it e.g. grid, text, radio, etc...

We should be able to have a default template that grabs all variable IDs or labels and its variables and display it into 2 columns. Furthermore, with the control ID e.g. grid, radio, etc we should be able to CSS it for the output document so that everything appears nice and clean on the output document. Sort of like a “for each...then..” variable
#813502
PipSqueak wrote:We should be able to have a default template that grabs all variable IDs or labels and its variables and display it into 2 columns. Furthermore, with the control ID e.g. grid, radio, etc we should be able to CSS it for the output document so that everything appears nice and clean on the output document. Sort of like a “for each...then..” variable
CSS doesn't work in Output Documents due to the nature of the TCPDF library.
To output all the variables in a case, you can use this trigger code like this:
Code: Select all
//add the variables to exclude from output table:
$aVarsToExclude = array("APPLICATION", "INDEX", "APP_NUMBER", "PROCESS",
    "TASK", "PIN", "USER_LOGGED", "USR_USERNAME", "SYS_SYS", "SYS_LANG",
    "SYS_SKIN", "__ERROR__", "__VAR_CHANGED__"
    "reviewDate", "reviewDate_label");

//add the variables that should be shown even if blank:
$aVarsToShowIfBlank = array('reviewer', 'firstUserId');

$c = new Cases();
$aCase = $c->LoadCase(@@APPLICATION);
@=varList = array();
$counter = 1;

foreach ($aCase['APP_DATA'] as $varName => $varValue) {
    if (!in_array($varName, $aVarsToExclude) and 
        (!empty($varValue) or in_array($varName, $aVarsToShowIfBlank))) 
    {
        @=varList[$counter++] = array(
            "variable" => $varName,
            "value"    => $varValue
        );
    }
}
 
You can add the names of your variables to exclude and the variables which should always be printed.

Then, you can use this HTML code in your Output Document template:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<p></p>
<center><b>Case Variables</b></center>
<p></p>
<table style="border-collapse: collapse;" cellspacing="0" cellpadding="3" bordercolor="blue" border="1">
<tbody>
<tr><th><b>Variable</b></th><th><b>Value</b></th></tr>
<!-- @>varList -->
<tr>
<td>@#variable</td>
<td>@#value</td>
</tr>
<!-- @<varList --></tbody>
</table>
</body>
</html>
 
PipSqueak wrote:Is there a custom script or trigger that makes it easy for users to generate output document with a default template. For instance, each dynaform control already has an ID on it e.g. grid, text, radio, etc...
This trigger code used to work, but I just discovered that PMFDynaformFields() in not working in PM 3.2.1. I'm not sure in what version of PM it stopped working. You can try this if you have an older version of PM.

Trigger code:
Code: Select all
//Example outputting the variables in a DynaForm:

//set to the ID of the Dynaform:
$dynaformUID = '5568431605a99e771c4e9c4068144585'; 

//field types to print values:
$aPrintTypes = array('text', 'textarea', 'dropdown', 'suggest', 'checkbox', 'radio'); 

$aFields = PMFDynaFormFields($dynaformUID, @@APPLICATION, @%INDEX);
@@formVarsTable = '<table style="border-collapse: collapse;" '.
    'cellspacing="0" cellpadding="3" bordercolor="blue" border="1">'.
    "\n<tr><th>Field</th><th>Value</th></tr>\n";

foreach ($aFields as $aField) {
    if (in_array($aField->type, $aPrintTypes)) {
        @@formVarsTable .= "<tr><td>". $aField->label ."</td>".
            "<td>". $aField->value_label ."</td></tr>\n";
    }
}
@@formVarsTable .= "</table>";  
Then, the Output Document contains:
Code: Select all
@#formVarsTable
#813549
Hi Amos,

It worked! Thank you very much! Can we put this thread in the "Tips & Tricks" section? I used your trigger before output document, love it!

Took away exclude and ifblank to make it generic ;)
Code: Select all
$c = new Cases();
$aCase = $c->LoadCase(@@APPLICATION);
@=varList = array();
$counter = 1;

foreach ($aCase['APP_DATA'] as $varName => $varValue) {
    if (!in_array($varName) and 
        (!empty($varValue) or in_array($varName))) 
    {
        @=varList[$counter++] = array(
            "variable" => $varName,
            "value"    => $varValue
        );
    }
}
#813596
By the way, how do I
1) only grab the labels of the form controls/fields (e.g. questions "What is your name?")
2) only the <variable>_label? Right now, it's display 1st row: <variable>, 2nd row <variable>_label, etc.

Sorry, I realized I edited my previous post as I figured it out the same time you replied my post. Thanks very much for your help!

Being the best in the started business is the obje[…]

Winzo is a popular and unique game on the mobile p[…]

Cannot create process using templets

Real details. The problem was solved by effect!

However, it is essential to use it responsibly and[…]