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

Moderator: amosbatto

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
Value Based Assignment to group

Thanks for reply. How to use if condition in your […]

extract ip of server

Thank you

A guide to install PM 4

Hi, You can check this link:[…]

Getting finish all the coursework within tight dea[…]