Page 1 of 1

CREATE NEW TRIGGER

Posted: Mon Feb 11, 2019 2:47 am
by dhanaulia
How to create new custom trigger with code in rest api?

Re: CREATE NEW TRIGGER

Posted: Mon Feb 11, 2019 3:53 am
by ziadeh
You can create a trigger in PM designer and call it from rest api read this

Also if you want to create a custom code and call it from rest api, you have to create a php file in
Code: Select all
{Your processmaker path}/workflow/engine/src/ProcessMaker/Services/Api
There are couple of test files so you can get some ideas from them.

After you create a rest api php file and made your custom code you need to delete routes.php file:
Code: Select all
{Your processmaker path}/shared/sites/workflow/routes.php
And PM will generate a new one that have your code.

Also you can use Extrarest api for Amosbatto

Re: CREATE NEW TRIGGER

Posted: Mon Feb 11, 2019 4:48 am
by dhanaulia
can i just try it at postman without create new php file?

Re: CREATE NEW TRIGGER

Posted: Mon Feb 11, 2019 4:16 pm
by ziadeh
Yes you can, please read this documentation: https://wiki.processmaker.com/3.0/REST_ ... te_trigger

Re: CREATE NEW TRIGGER

Posted: Mon Feb 11, 2019 10:04 pm
by amosbatto
If you want to add a new trigger functions, then you create a plugin with the PMFunctions Class.

Then you need to add comments in this file of your new plugin:
pluginName/classes/class.pmFunctions.php.

You can study the source code in my extraFunctions plugin for an example:
https://www.pmusers.com/index.php/ExtraFunctions_plugin

Re: CREATE NEW TRIGGER

Posted: Thu Feb 21, 2019 4:11 am
by dhanaulia
i create new trigger with code using postman. it was success, but when i open in website, code is gone and type change to wizard. can anyone help me?

Re: CREATE NEW TRIGGER

Posted: Thu Feb 21, 2019 4:06 pm
by amosbatto
Can you export your plugin and post the .tar file here (or post your pluginName/classes/class.pmFunctions.php file)?

Also, what version of Processmaker?, manual or bitnami install? What operating system?

Re: CREATE NEW TRIGGER

Posted: Thu Feb 21, 2019 11:30 pm
by dhanaulia
I didn't have a code plugin. Is really necessary to create php file? but i just trying to create new trigger with code. because i trying in website and completely fine. i just copy my code in web and paste in postman. but the result was different (i try in postman, and type change to wizard)

Re: CREATE NEW TRIGGER

Posted: Thu Feb 21, 2019 11:31 pm
by dhanaulia
im using processmaker 3.3.2 with VM Centos 7 and manual install

Re: CREATE NEW TRIGGER

Posted: Fri Feb 22, 2019 9:06 pm
by amosbatto
Oh, sorry, I thought you were creating a plugin with a new function.

If you want to create a trigger using REST, then see:
https://wiki.processmaker.com/3.0/REST_ ... te_trigger

Re: CREATE NEW TRIGGER

Posted: Sat Feb 23, 2019 11:03 am
by dhanaulia
i followed your instructions and response was 200 but i open that trigger in website, trigger type turns become wizard (it happened if i add some tri_webbot). but if i create new trigger without add code in tri_webbot, when i open my trigger in website its normal. how can i adding some code in tri_webbot without error like that?

Re: CREATE NEW TRIGGER

Posted: Tue Feb 26, 2019 3:37 am
by amosbatto
I got it to work by setting tri_param to "" (an empty string).

Here is the PHP code I used:
Code: Select all
	$processId = '2606490355c64d95da1c7d2093841486';
	
	$aVars = array(
	    "tri_title"      => "Set products list 2",
		"tri_description"=> "short list of products 2",
		"tri_type"       => "SCRIPT",
		"tri_webbot"     => "@=aProducts = array(
	array('hello', 'Hello'),
	array('kitty', 'Kitty')
);
@@test = 2;",
		"tri_param"      => ""
	);

	$url = "/api/1.0/workflow/project/$processId/trigger";
	$oRet = pmRestRequest("POST", $url, $aVars, $oToken->access_token);

Re: CREATE NEW TRIGGER

Posted: Wed Feb 27, 2019 3:47 am
by dhanaulia
its work, thankyou