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.
By njhajhajha
#817566
Hey,

I am using Process maker 3.2.2 community version,
Actually i want to show success message in routing template ,So if you have any running example of the template(.html).
I have seen example on Process maker link but throws error in my case.


Thank You
By andreaadamczyk
#817567
Hello,

In this file: "<INSTALL-DIRECTORY>/processmaker/workflow/engine/template/cases/cases_ScreenDerivation.html" you could see an entire example of a template you can use in a routing screen, this is the default template, and you can modify it according to your needs.

For more information see: https://wiki.processmaker.com/3.2/Templ ... n_Template

Hope it helps you.

Regards.
By nobody
#818023
This may come late but attached you may find a working example.
I tried to pass the case variables to the routing screen, but failed to get the access token. While this is very easy when in a dynaform (just put MFDynaform.getAccessToken() to the dynaform's javascript), I was not able to get it when on the routing screen. I spent hours trying to figure this out but ended up with a workaround to store the case vars in the local storage.
Note the following disadvantages:
1. NEVER store sensitive data (such as access token) in the local storage.
2. This only works with IE8 and later.

My workaround was to place in the dynaform's javascript the following:
Code: Select all
//this is a workaround to store variables in the local storage
//NEVER store sensitive information in the local storage!!!

$("form").setOnSubmit(function(){  //when submitting the form, save the selected vars in local storage
  $("form").saveForm();
//store the vars in an object 
  var vars = {
    'entity': $("#entity").getValue(),
    'round': $("#votingRound").getValue(),
    'vote': $("#vote").getText(),
    'score': $("#totalScore").getValue()
    
  }
 if(localStorage.getItem('variables')=== null){
   localStorage.setItem('variables', JSON.stringify(vars)); //create key->value like pairs to be stored in the local storage
  } else {
      localStorage.removeItem('variables');  //remove the vars from the local storage if allready in there
      localStorage.setItem('variables', JSON.stringify(vars));

  }});
In your copy of the routing screen template, add HTML like this (follow the instructions from wiki to place it in the correct sections)
Code: Select all
<tr>
					<!--Make sure the file exists in the /workflow/engine/public_html/images directory-->
				<td style="text-align: center" colspan="2"><img src="/images/toadd.png"/></td>
			</tr>
			<tr>
				<td style="text-align: center" colspan="2"><h2 style="color: red">CHECK YOUR VOTING!</h2></td>
			</tr>
			<tr height="5">
				<td class="FormLabel" width="100">Entity:</td>
				<td class="FormFieldContent"><p id="entity"></p></td>
			</tr>
			<tr height="5">
				<td class="FormLabel" width="100">Voting round:</td>
				<td class="FormFieldContent"><p id="round"></p></td>
			</tr>
			<tr height="5">
				<td class="FormLabel" width="100">Your vote:</td>
				<td class="FormFieldContent"><p id="vote"></p></td>
			</tr>
			<tr height="5">
				<td class="FormLabel" width="100">Score:</td>
				<td class="FormFieldContent"><p id="score"></p></td>		  
			</tr>
			<tr>
			</tr>
			<tr>
				<td style="text-align: center" colspan="2"><h4 style="color: blue">If the data is correct, click Continue.</br> Otherwise, click on the previous step link.</h4></td>
			</tr>
In the javascript section of your routing screen template, put the following:
Code: Select all
var variables = localStorage.getItem('variables'); //get the variabes stored in the local storage
 var varsObject = JSON.parse(variables); //create an object from the vars
	 for (var key in varsObject) { //itterate
	 if (document.getElementById(key) !== null){
	 document.getElementById(key).innerHTML = varsObject[key]; //populate the HTML element with the variables
	 }}
	localStorage.removeItem('variables'); //CLEAR the local storage
My routing screen looked like this (I used a different image, the toadd.img is by default in the images directory):

Image
The working routing screen template is attached.
Attachments
Add description
(14.89 KiB) Downloaded 288 times
By nobody
#818057
Thanks Amos, I am not very happy with how fragile an insecure this is, but could not figure out how to get the access token of the current user when not in dynaform.
User avatar
By amosbatto
#818061
We don't have a good way to get the access token (except to use Javascript and do a login with REST and that would be insecure if the password is included in the JavaScript code).

Inside a trigger or in the ProcessMaker source code, you can use the following PHP code in version 3.2.2 and later:
Code: Select all
    require_once PATH_CONTROLLERS . 'designer.php';
    $designer = new Designer();
    $credentials = $designer->getCredentials();
This sets $credentials to:
Code: Select all
array(
    "access_token" =>" 8bd11f036a5b5eb9e98eb20d8c7375e29bc05fcc", 
    "expires_in" => 86400, 
    "token_type" => "bearer", 
    "scope" => "view_processes edit_processes *", 
    "refresh_token" => "4e2b737f675a5a3a8b9a79b11ba8af40fd4e02e2", 
    "client_id" => "xxxxxxxx",
    "client_secret" => "xxxxxxxxx"
)
For older versions, see:
viewtopic.php?f=44&t=713519&p=795087#p795087

Then, the access_token has to be passed to the form, when it is generated. If you add a hidden field whose ID and name is "access_token" in your custom template file, then you can edit your /workflow/engine/methods/cases/cases_Step.php file and in line 1114 change from:
Code: Select all
                    $aFields['webEntryUrlEvaluated'] = $webEntryUrlEvaluated;
                }
To:
Code: Select all
                    $aFields['webEntryUrlEvaluated'] = $webEntryUrlEvaluated;
                    require_once PATH_CONTROLLERS . 'designer.php';
                    $designer = new Designer();
                    $credentials = $designer->getCredentials();
                    $aFields['access_token'] = $credentials['access_token'];
                }
Then, you can use JavaScript in your custom template to get the value of the "access_token" hidden field.
By nobody
#818072
Thank you, I should have mentioned I did not want to change the PM source code and the example for the older version is exactly what I have been looking for.
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]