Un foro de discusión para nuestra comunidad de hispano hablante

Moderator: amosbatto

#821785
Buen dia, Amigos:

Quería molestarlos necesito un trigger que me ayude a bloquear un caso nuevo, cuando ya se encuentre otro caso del mismo usuario en estado "ABIERTO", ya que solo puede existir un caso del mismo proceso por usuario he intentado con el siguiente pero no me funciona, lo coloco antes de Dynaform pero igual se logra colar. Alguna opción por favor. De antemano muchas gracias.
Code: Select all
//assign system variables to PHP variables so can be inserted in strings
 $user = @@USER_LOGGED; 
 $process = @@PROCESS;
 //Query to find any uncompleted steps assigned to logged-in user
 $query = "SELECT * FROM APP_DELEGATION WHERE PRO_UID='$process' AND 
   USR_UID='$user' AND DEL_THREAD_STATUS='OPEN'";
 $res = executeQuery($query);
 //if any open tasks are are found, assigned to user: 
 if (is_array($res) and count($res) >= 1)
 {
    $c = new Cases();
    $c->removeCase(@@APPLICATION); //delete the existing case
    //Look up info on the existing case:
    $caseId = $res[1]['APP_UID'];
    $resExisting = executeQuery("SELECT * FROM APPLICATION WHERE APP_UID='$caseId'");
    $caseNo = $resExisting[1]['APP_NUMBER'];
    $caseId = $resExisting[1]['APP_UID'];
    $caseIdx = $caseId = $resExisting[1]['APP_INDEX']; 
    //Finally display message to user to first complete other case and redirect to the existing case 
   $g = new G();
   $g->SendMessageText("Case Aborted. Please complete or cancel this Case #$caseNo before starting a new case", 'WARNING');
    G::header("Location: cases_Open?APP_UID=$caseId&DEL_INDEX=$caseIdx")
    die(); //abort trigger to prevent any errors
 }
#821787
Tu busqueda en la base de datos no debe incluir el caso actual. Tambien G::header() no funciona en versiones recientes de PM, entonces debes usar header().
(¿Dónde has conseguido este código? Quiero actualizarlo.)

Bueno, puedes probar este código:
Code: Select all
//assign system variables to PHP variables so can be inserted in strings
$user = @@USER_LOGGED; 
$process = @@PROCESS;
$currentCase = @@APPLICATION;
//Query to find any uncompleted steps assigned to logged-in user
$query = "SELECT * FROM APP_DELEGATION WHERE PRO_UID='$process' AND 
   USR_UID='$user' AND DEL_THREAD_STATUS='OPEN' and APP_UID<>'$currentCase'";
$res = executeQuery($query);

//if any open tasks are found which are assigned to the user: 
if (is_array($res) and count($res) >= 1) {
    $c = new Cases();
    $c->removeCase(@@APPLICATION); //delete the existing case
    //Look up info on the existing case:
    $caseId = $res[1]['APP_UID'];
    $resExisting = executeQuery("SELECT * FROM APPLICATION WHERE APP_UID='$caseId'");
    $caseNo = $resExisting[1]['APP_NUMBER'];
    $caseId = $resExisting[1]['APP_UID'];
    $caseIdx = $caseId = $resExisting[1]['APP_INDEX']; 
    //Finally display message to user to first complete other case and redirect to the existing case 
    $g = new G();
    $g->SendMessageText("Case Aborted. Please complete or cancel this Case #$caseNo before starting a new case", 'WARNING');
    header("Location: cases_Open?APP_UID=$caseId&DEL_INDEX=$caseIdx")
    die(); //abort trigger to prevent any errors
 }
#821852
Tu query "SELECT count(*) FROM APP_DELEGATION ..." siempre devolverá 1 fila, entonces no funcionará.
Debes usar: "SELECT * FROM APP_DELEGATION ..." si quieres usar count($res) para contar el número de filas.

Si utilizas este trigger antes del primer Dynaform, tendras un bucle infinitivo. Va a redirigir al primer Dynaform, que executa el trigger que redirige al primer Dynaform, que executa el trigger, ...

He agregado código para cortar el bucle. He probado este trigger en PM 3.2.3:
Code: Select all
if (!empty(@@redirected)) {
	@@redirected = null;
}
else {
	$user = @@USER_LOGGED; 
	$process = @@PROCESS;
	$currentCase = @@APPLICATION;
	$query = "SELECT * FROM APP_DELEGATION WHERE PRO_UID='$process' AND 
   		USR_UID='$user' AND DEL_THREAD_STATUS='OPEN' AND APP_UID<>'$currentCase'";
	$res = executeQuery($query);

	if (is_array($res) and count($res) > 0) {
		@@retDelete = PMFDeleteCase(@@APPLICATION);
    		$caseId = $res[1]['APP_UID'];
    		$caseIdx = $res[1]['DEL_INDEX']; 
	
    		//Display message to user to complete the existing case and redirect to it 
    		$g = new \G();
    		$g->SendMessageText("Other case aborted. Please complete or cancel this case before starting a new case.",
							'WARNING');
		PMFSendVariables($caseId, array('redirected' => $currentCase));
		echo "<script> top.location='opencase/$caseId'; </script>";	
		
		//Note: if ProcessMaker is used inside an iframe in another web page, then use this code instead:
		//header("Location: cases_Open?APP_UID=$caseId&DEL_INDEX=$caseIdx");
 
		die(); //abort trigger to prevent any errors
	}
}
Ahora va a redirigir al caso existente y mostrar un mensaje:
redirectedToCase.png
redirectedToCase.png (67.45 KiB) Viewed 1295 times
#823158
hello all;
we want to change this code to work when any case is still in drafts state no cases in other status and caseNo Does not increase; please help.
Code: Select all
//assign system variables to PHP variables so can be inserted in strings  
$user = @@USER_LOGGED; 
$process = @@PROCESS;
//Query to find any uncompleted steps assigned to logged-in user
$query = "SELECT * FROM APP_DELEGATION WHERE PRO_UID='$process' AND ".
         "USR_UID='$user' AND DEL_THREAD_STATUS='OPEN'";
$res = executeQuery($query);

//if any open tasks are are found, assigned to user
if (is_array($res) and count($res) >= 2){
   $c = new Cases();
   $c->removeCase(@@APPLICATION); 
   $query = "SELECT * FROM APP_DELEGATION WHERE PRO_UID='$process' AND ".
            "USR_UID='$user' AND DEL_THREAD_STATUS='OPEN'";
   $res = executeQuery($query);
   $casesId = $res[1]['APP_UID'];
   $resExisting = executeQuery("SELECT * FROM APPLICATION WHERE ".
                               "APP_UID='$casesId'");
   $caseNo = $resExisting[1]['APP_NUMBER'];
   $caseId = $resExisting[1]['APP_UID'];
   $delindex = executeQuery("SELECT DEL_INDEX FROM APP_DELEGATION ".
                            "WHERE APP_UID='$caseId'");
   $caseIdx = $delindex[1]['DEL_INDEX']; 

   //Finally display message to user to first complete other case 
   //and redirect to the existing case
$g = new G();
$g->SendMessageText("". "$caseNo ", '');
   G::header("Location: cases_Open?APP_UID=$caseId&".
             "DEL_INDEX=$caseIdx&action=draft");
   die();    
}
#823170
atbmbk wrote: Thu Feb 28, 2019 6:16 am hello all;
we want to change this code to work when any case is still in drafts state no cases in other status and caseNo Does not increase; please help.
Your English is not clear. Do you want to allow new cases to be created when other cases are in "Draft" status, but no cases are in "To Do" or "Paused" status? If there is another case in "To Do" or "Paused" status, then delete the current case and redirect the web browser to that other case. Is that what you want?
#823178
amosbatto wrote: Thu Feb 28, 2019 11:45 pm
atbmbk wrote: Thu Feb 28, 2019 6:16 am hello all;
we want to change this code to work when any case is still in drafts state no cases in other status and caseNo Does not increase; please help.
Your English is not clear. Do you want to allow new cases to be created when other cases are in "Draft" status, but no cases are in "To Do" or "Paused" status? If there is another case in "To Do" or "Paused" status, then delete the current case and redirect the web browser to that other case. Is that what you want?

Thanks for your attention ; You are right ; Sorry ; we dont want to delete any cases in "To Do" or "Paused" or other status ; we want dont allow new case A when we have case A in "Draft" status and when this happend redirect the web browser to that case A is in "Draft" status;
Hope explain it well;
Thanks .
Task doesnt have any users.

I have created a small process. Users are assigned[…]

NEW MOBILE APP ISSUE

Just trying to setup to use the mobile App with my[…]

It's really a great idea. I have followed the seco[…]

yes i use php thanks for the information