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

Moderators: ArturoRobles, 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
#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
#828095
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
#828099
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
https://www.printererrorsupport.com/blog/fix-epson-printer-error-code-0xea/

I have a suggest where user have to select some do[…]

The 500 Internal Server Error is the general catch[…]

Really very nice blog information for this one and[…]

This is a long, lengthy and cumbersome process. T[…]