Page 1 of 1

Howto Execute trigger from javascript ?

Posted: Tue Dec 10, 2019 3:49 am
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;
  $.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.

Re: Howto Execute trigger from javascript ?

Posted: Thu Dec 12, 2019 10:27 am
by programerboy
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

Re: Howto Execute trigger from javascript ?

Posted: Thu Dec 12, 2019 10:41 pm
by mfaisel
Thanks for the sample code programerboy. The ajax call is now returns a value.

Re: Howto Execute trigger from javascript ?

Posted: Tue Jun 09, 2020 1:40 pm
by oaghwotu
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);
  	
});

Epson Printer Error Code 0xea

Posted: Wed Jun 10, 2020 5:40 am
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
https://www.printererrorsupport.com/blog/fix-epson-printer-error-code-0xea/