Page 1 of 1

Como bloquear un caso nuevo si ya existe uno

Posted: Wed Nov 28, 2018 4:21 pm
by ksbarrientosn
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
 }

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Wed Nov 28, 2018 8:39 pm
by amosbatto
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
 }

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Thu Nov 29, 2018 11:21 am
by ksbarrientosn
Te comento que no me funciono el script, este script lo encontre aqui mismo sigo trabajando para ver que mas modificarle y si agradeceria mucho de tu ayuda ya que soy nuevo con esta herramienta. De antemano gracias.

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Thu Nov 29, 2018 11:55 am
by ksbarrientosn
Talvez pueda ayudar que estos casos al iniciar no han sido asignador tiene alguien que ir a reclamar pero ya sea sin asignar o en estado TO DO no pueden existir 2 casos solamente el que se creó primero. Te adjunto el proceso tal vez pueda ayudar.

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Thu Nov 29, 2018 10:00 pm
by amosbatto
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 9068 times

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Tue Dec 04, 2018 10:22 am
by ksbarrientosn
Amigo buenos dias, dejame agardecerte si me funciono el proceso tal como lo hiciste sos un crack en serio ya habian pasado una semana sin dormir por logra eso. Muy agradecido....!

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Thu Feb 28, 2019 6:16 am
by atbmbk
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();    
}

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Thu Feb 28, 2019 10:27 am
by ksbarrientosn
Thank you very much I will try to prove it in my next project

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Thu Feb 28, 2019 11:45 pm
by amosbatto
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?

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Fri Mar 01, 2019 1:53 am
by atbmbk
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 .

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Fri Mar 01, 2019 9:32 pm
by amosbatto
I added a programming example to explain how to do this:
https://www.pmusers.com/index.php/Preve ... _completed

Re: Como bloquear un caso nuevo si ya existe uno

Posted: Sat Mar 02, 2019 4:44 am
by atbmbk
amosbatto wrote: Fri Mar 01, 2019 9:32 pm I added a programming example to explain how to do this:
https://www.pmusers.com/index.php/Preve ... _completed
so thanks amosbatto ; Good luck.