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
#827124
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;
  $.ajax({ 
    url: execute_trigger_url,   
    data: { abc: 'DEF' },  		
    type: "PUT",
    beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Bearer ' + token);},
    success: function(put_data){        
      console.log(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.
#827150
Hi,
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(){
	$.ajax({
	  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) {
         alert(msg)
	  if (msg.error) {
               alert(false)
	  } else {
		alert(true)
	  }
	});
}
https://www.youtube.com/channel/UCYiyz1 ... 1iw/videos
Thanks
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: https://github.com/P[…]

Getting finish all the coursework within tight dea[…]