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.
User avatar
By mdbarber
#822312
Hello,

I am trying to send a dynaform by email to a user. This user does not need to interact with the dynaform, but only have a visual copy of it.

A colleague has tried using the PM API. This works but only to a certain extent. We have two issues with the API since it returns the values of the inputs rather than the DOM:

- Checkgroups do not return a value
- If the dynaform is modified with JS, these changes are not passed on to the email
(for ex: If I choose to hide an input with JS, the said input will still be visible in the email)

Therefore I was wondering if it is possible to send a copy of the DOM on submit by email?

Any help would be greatly appreciated,

Maxime
User avatar
By amosbatto
#822320
mdbarber wrote:A colleague has tried using the PM API.
Are you talking about the ProcessMaker REST API? If so, which endpoint are you using? The endpoints to get variables should work with checkgroups. If you aren't seeing that, then what version of PM are you using and what version of PHP?
mdbarber wrote:Therefore I was wondering if it is possible to send a copy of the DOM on submit by email?
There is not easy way to do this. You could create an email template which includes the JavaScript code to hide fields, but not all email clients allow JavaScript code to execute.
The easiest way to get around this problem is to email the person the case number and PIN, so he/she can login using the Case Tracker to view the Dynaform.

Remember, that if you are using JavaScript to hide a field, then you need the code to execute both when the form loads and when the user changes the value of a field, like this:
Code: Select all
function showOrHideField(newVal, oldVal) {
    if (newVal == 'X') {
       $("#somefield").hide();
    }
    else {
       $("#somefield").show();
    }
}
$("#myfield").setOnchange(showOrHideField); //execute when value changes
showOrHideField( $("#myfield").getValue(), ''); //execute when form loads
That way it will work correctly when viewed in the Case Tracker.

The other solution is to create the content of the email dynamically in a trigger which is executed after the Dynaform.
For example if your email template contains the following HTML:
Code: Select all
<b>Variable 1:</b>  @#variable1<br>
@#dynamicContent
<b>Variable 2:</b>  @#variable2<br>
Then, you can set the value of @#dynamicContent in your trigger:
Code: Select all
if (@@myfield == 'X') {
    @@dynamicContent = ''; //do not include somefield
} else {
   @@dynamicContent = "<b>Some Field:</b> ". @@somefield ."<br>";
}
PMFSendMessage(@@APPLICATION, $from, $to, $cc, $bcc, 'my email subject', 'mytemplate.html', 
    array('dynamicContent'=>@@dynamicContent));
There is third option to use JavaScript to grab that HTML code of the form and store it in a hidden variable when the Dynaform is submitted. Then in a trigger fired after the Dynaform, you can delete the field from the HTML if it needs to be hidden. Then include that HTML in your email template with a variable, as shown above.

If you want to include a checkgroup in an email or output document, then see:
https://www.pmusers.com/index.php/Check ... and_Emails
User avatar
By mdbarber
#822343
Thank you for your response.

amosbatto wrote:Are you talking about the ProcessMaker REST API? If so, which endpoint are you using? The endpoints to get variables should work with checkgroups. If you aren't seeing that, then what version of PM are you using and what version of PHP?
Yes, using the GET Dynaform and GET Case Variables endpoints. I am using PM 3.2.1 and PHP 5.6.

amosbatto wrote:The easiest way to get around this problem is to email the person the case number and PIN, so he/she can login using the Case Tracker to view the Dynaform.
Unfortunately, this is not an option.

amosbatto wrote: The other solution is to create the content of the email dynamically in a trigger which is executed after the Dynaform.
The problem with this solution is that I have many dynaforms with this issue. Therefore, it would be very time consuming to review every template.

amosbatto wrote:There is third option to use JavaScript to grab that HTML code of the form and store it in a hidden variable when the Dynaform is submitted. Then in a trigger fired after the Dynaform, you can delete the field from the HTML if it needs to be hidden. Then include that HTML in your email template with a variable, as shown above.
It seems I will try the third option and see how that goes.

Edit 1:

This solution worked, only partially though. Checkboxes, Checkgroups and Radio buttons are not displayed as checked but with the correct value displayed below, as seen in the attached file. I guess this is due to the fact PM dynaforms are checked via a hidden input.

Any ideas on how to solve this issue?

Edit 2:

Problem solved by adding this code in the JS:
Code: Select all
// On submit, set hidden input with form
$("#submit").click(function ()
{
    // Store form in variable
    var form = document.getElementsByTagName("form");
    var dom = form[0];

    var inputs = document.getElementsByTagName('input');

    for (var i = 0; i < inputs.length; i++)
    {
        if (inputs[i].type.toLowerCase() == 'checkbox' || inputs[i].type.toLowerCase() == 'radio')
        {
            if (inputs[i].checked)
            {
                inputs[i].setAttribute('checked', '');
            }
        }
    }

    // Store hidden fields in variable
    var hiddenFields = $("[class$='content-print']");

    for (var i = 0; i < hiddenFields.length; i++)
    {
        hiddenFields[i].style.display = "none";
    }

    $("#dynaform").setValue(dom.outerHTML);
})
Thanks a lot for your help amosbatto.
Attachments
Screenshot 2019-01-10 at 16.28.52.png
Screenshot 2019-01-10 at 16.28.52.png (10.64 KiB) Viewed 2172 times

Hello Please can you help me with the place where […]

Hi there, I have 3.5.7, 3.8.1 and 3.8.2 versi[…]

AI bot development involves creating intelligent b[…]

AI bot development encompasses creating intelligen[…]