Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: ArturoRobles

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 mfaisel
Following suggestion posted in Suggested in viewtopic.php?t=709685#p787545

I am trying to execute a 'trigger' code when a button is clicked. FYI, I have constructed the following codes with debug mode enabled.

1st trigger before dynaform - to set a hidden variable named 'app_uid' in the dynaform
Code: Select all
@@app_uid = @@APPLICATION;
The dynaform JavaScript
Code: Select all
var host = PMDynaform.getHostName();              // get the hostname
var ws = PMDynaform.getWorkspaceName();           // get the current workspace
var token = PMDynaform.getAccessToken();          // get the access Token

var apiServer = location.protocol + '//' + host + '/api/1.0/' + ws;
var app_uid = $('#app_uid').getValue();
var trigger_uid  = '6882411815dedfb9a234b33075746263';

// myBtn OnClick event
$("#myBtn").on("click", function(){
  let execute_trigger_url = apiServer + "/cases/" + app_uid + "/execute-trigger/" + trigger_uid;
    url: execute_trigger_url,   
    data: { abc: 'DEF' },  		
    type: "PUT",
    beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Bearer ' + token);},
    success: function(put_data){        
  return false;  //return false to stop submit action
2nd trigger (UID:6882411815dedfb9a234b33075746263) to be executed in the above JavaScript code
Code: Select all
error_log('OK'); // sent to apache's error.log
echo 'OK';
Problem: I was not able to locate the word 'OK' anywhere not in the debugger window, not in browser's Web Developer console and not in Apache's error.log

I am very sure that the 'success:' block was not executed.

Please assist.
Thank you.
This is an tested code for use ajax in your form:
Code: Select all
var host = PMDynaform.getHostName();
var ws = PMDynaform.getWorkspaceName();
var token = PMDynaform.getAccessToken(); 
var app_uid = PMDynaform.getProjectKeys().caseUID;
var trig_uid = "3259996315cd920c9e4b849014483800";

function my_function(){
	  type : 'PUT',
	  url: host+'/api/1.0/'+ws+'/cases/'+app_uid+'/execute-trigger/'+trig_uid,
	  data : {
		id : $('#id').getValue()
	  beforeSend: function(xhr) {
		xhr.setRequestHeader('Authorization', 'Bearer '+token);
	}).done(function (msg) {
	  if (msg.error) {
	  } else {
} ... 1iw/videos
Hello there. Please I need your help. My app_uid is returning null . It is a subform embedded in another form
Code: Select all
const app_uid = PMDynaform.getProjectKeys().caseUID;

Here is my code
Code: Select all
const host = PMDynaform.getHostName();
const ws = PMDynaform.getWorkspaceName();
const app_uid = PMDynaform.getProjectKeys().caseUID;
const token = PMDynaform.getAccessToken();
Code: Select all
$(document).ready(function() {
   console.log("host: " + host);
   console.log("ws: " + ws);
   console.log("app_uid: " + app_uid);
   console.log("token: " + token);
Last edited by oaghwotu on Sun Jun 14, 2020 7:34 am, edited 1 time in total.
By elisamartin08
I highly appreciate the content and information in the blog which provided with the widening of the idea and understanding the topic. It really helped me understand the information.
visit us
Code: Select all

Any ideas in this regard? Thanks

Can anyone help me please??????

rabbidwombat, I have created a better code examp[…]

Processmaker 3.6.1 OpenSource?

Generally, they share the latest release source co[…]