Page 1 of 1

create function with modify dynaforms inside of it makes error

Posted: Wed Jun 17, 2020 10:54 am
by GianYagami
hi,

I found something might be interested.
I create this trigger:
Code: Select all
function test_function($USERNAME)
{
	$query = "SELECT USR_UID FROM USERS WHERE USR_USERNAME = '$USERNAME'";
	$res = executeQuery($query);
	@@DeptHeadUID = $res['USR_UID'];
}

function test_function2()
{
	$query = "SELECT USR_UID FROM USERS WHERE USR_USERNAME = 'GianYagami'";
	$res = executeQuery($query);
	@@DeptHeadUID = $res['USR_UID'];
}

function foo(){
	return 2 + 2;
}

foo(); //he's cool

//test_function('GianYagami'); //he's not cool

//test_function2(); //this dude also not cool

//$array = new array("USERNAME" = "31406193");
//test_function3($array); //i forgot to make this one, lol
modify dynaform variable inside of user created function makes the code error, I am using PM 3.3

Re: create function with modify dynaforms inside of it makes error

Posted: Sun Jun 21, 2020 8:43 pm
by erico28
Hi,

thanks for sharing !quite interesting indeed ! :)

Re: create function with modify dynaforms inside of it makes error

Posted: Wed Jun 24, 2020 2:30 pm
by programerboy
Hi,
You must change your codes like this:
Code: Select all
function test_function($USERNAME)
{
	$query = 'SELECT USR_UID FROM USERS WHERE USR_USERNAME = "'.$USERNAME.'"';
	$res = executeQuery($query);
	return $res['USR_UID'];
}

@@DeptHeadUID = test_function('GianYagami');
or 
@@DeptHeadUID = test_function(@@USER_LOGGED);
Please check the following link:
http://pmlearning.info/plugins.php

Re: create function with modify dynaforms inside of it makes error

Posted: Tue Jul 07, 2020 11:36 pm
by GianYagami
programerboy wrote: Wed Jun 24, 2020 2:30 pm Hi,
You must change your codes like this:
Code: Select all
function test_function($USERNAME)
{
	$query = 'SELECT USR_UID FROM USERS WHERE USR_USERNAME = "'.$USERNAME.'"';
	$res = executeQuery($query);
	return $res['USR_UID'];
}

@@DeptHeadUID = test_function('GianYagami');
or 
@@DeptHeadUID = test_function(@@USER_LOGGED);
Please check the following link:
http://pmlearning.info/plugins.php
I already implemented it for different cases,
using return and/or "parameterized" function also makes error.
I think trigger script is implemented as function my processmaker engine so we can not create function unless the function has no parameter and return value, I dunno it just my speculation.

Anyway this topic is already fixed using procedural way instead reusable function (I am not using function anymore)