Share ideas, ask questions, and get feedback about developing for ProcessMaker
Forum rules: Please post new questions under "Developing processes & programming" for ProcessMaker 2 or 3.
By darshana
#786368
hello,
i want to generate new case depending upon the time duration.let me explain what i want to do.

I have dynaform where user fills the form for servicing and select the type of service whether it is regular servicing or adhoc servicing and gives servicing frequency and depending upon that frequency new case should be generated every time for regular servicing.what should i do??
By darshana
#786401
Thank you that problem is solved now.But now i want generate that case after specific time.I mean now if user enters his servicing frequency as 3 months then task should generate after 3 months in his inbox not now.my due date is showing its date after 3 months but from now i can't assign that task to user.What should i do.
User avatar
By amosbatto
#786421
Hi darshana,
There is no easy way to do this, but I suggest that you create 2 processes to handle this.
1. Create the first process named "Service" which will be executed regularly or on an ad hoc basis to provide services to your clients.

2. Create a second process named "Configure Services" which contains the DynaForm where you set whether it is a single adhoc case or periodic (regular) cases. Use a variable named "ServiceType" with a dropdown whose keys can "adhoc" or "periodic". Then add the following trigger which is set to fire after the DynaForm:
Code: Select all
if (isset(@@ServiceType) and !empty(ServiceType)) {
  if (@@ServiceType == 'adhoc') {
    //data to pass to the Service case
     $aVars = array(
         'ServiceType' =>  @@ServiceType,
         'clientName'   =>   @@clientName,
         'clientPhone'  =>   @@clientPhone,
         //any other data you want to pass to the Service case
     );
     $processId = 'XXXXXXXXXXXXXXXXXXXX'; //set to the ID of your Service process
     $taskId  = 'XXXXXXXXXXXXXXXXXXX'; //set to the ID of the starting task in the Service process
     $userId  = 'XXXXXXXXXXXXXXXXXXXX'; //set to the ID of the user to be assigned to the Service case
    
     $newCaseId = PMFNewCase($processId, $userId, $taskId, $aVars);
     //if a new case was created, display a message in the next screen:
     if ($newCaseId) {
        $c = new Cases();
        $aCaseInfo = $c->LoadCase($newCaseId, 1);
        $msg = 'New Case #' . $aCaseInfo['APP_NUMBER'] . ' is assigned to ' . $aCaseInfo["CURRENT_USER"];
        G::SendMessageText($msg, 'INFO');
     }
     else {
        $msg = "Unable to create new case. " . isset(@@__ERROR__) ? @@__ERROR__ : '';
        G::SendMessageText($msg, 'ERROR');
     }
  }
}
As long as cases run in this process are not completed or cancelled, then the periodic "Service" cases will be started.

Then create a second trigger inside your "Configure Services" process with the following code to check whether to initiate regular cases or not for each case in the "Configure Services" process:
Code: Select all
$processId = @@PROCESS;
//look up every case in the Configure Services process which has a status of TO_DO or  DRAFT
$query = "SELECT * FROM APPLICATION WHERE PRO_UID='$processId' AND APP_STATUS in ('TO_DO', 'DRAFT')";
$aCases = executeQuery($query) or die("Unable to execute query: $query");

foreach($aCases as $aCase) {
   $aCaseVars = unserialize($aCase['APP_DATA']);
   if (isset($aCaseVars['ServiceType']) and $aCaseVars['ServiceType'] == 'periodic') {
        $aVars = array(
         'ServiceType' =>  $aCaseVars['ServiceType'],
         'clientName'   =>  $aCaseVars['clientName'],
         'clientPhone'  =>  $aCaseVars['clientPhone'],
         //any other data you want to pass to the Service case
     );
     $processId = 'XXXXXXXXXXXXXXXXXXXX'; //set to the ID of your Service process
     $taskId  = 'XXXXXXXXXXXXXXXXXXX'; //set to the ID of the starting task in the Service process
     $userId  = 'XXXXXXXXXXXXXXXXXXXX'; //set to the ID of the user to be assigned to the Service case
     $path = '/var/log/serviceCases.log'; //set to a writable file location on your server

     $newCaseId = PMFNewCase($processId, $userId, $taskId, $aVars);
     //if a new case was created, then write to a log file
     if ($newCaseId) {
        $c = new Cases();
        $aCaseInfo = $c->LoadCase($newCaseId, 1);
        $msg = 'New Case #' . $aCaseInfo['APP_NUMBER'] . ' is assigned to ' . $aCaseInfo["CURRENT_USER"] .
           ' for client ' . $aCaseVars['clientName'] . ' on ' . date('Y-m-d h:i:s') . "\n";
     }
     else {
        $msg = "Error: Unable to create new case for client ' . $aCaseVars['clientName'] . ' on ' . date('Y-m-d h:i:s') . "\n" . 
              (isset(@@__ERROR__) ? @@__ERROR__ ."\n" : '');
     }
     file_put_contents($path, $msg, FILE_APPEND);
  }
}   
Do NOT set the above trigger to execute. It will be executed by web services.

3. Create an external script file which uses ProcessMaker web services to execute the above trigger periodically:
#look up the caseId and delIndex with the caseList() web service and the triggerIndex in MySQL
Code: Select all
<?php
ini_set("soap.wsdl_cache_enabled", "0");
ini_set('error_reporting', E_ALL);
ini_set('display_errors', True);
   
$client = new SoapClient('http://localhost/sysworkflow/en/neoclassic/services/wsdl2');
$pass = 'md5:' . md5('P@SsW0rD');
$params = array(array('userid'=>'admin', 'password'=>$pass));
$result = $client->__SoapCall('login', $params);
 
if ($result->status_code == 0)
   $sessionId = $result->message;
else
   print "Unable to connect to ProcessMaker.\nError Number: $result->status_code\n" .
         "Error Message: $result->message\n";
         
$triggerId = 'XXXXXXXXXXXXXXXXXXXXXXX'; //set to ID of trigger
$caseId = 'XXXXXXXXXXXXXXXXXXXXXXX';  //set to the ID of any open case in the "Configure Services" process
$params = array(array('sessionId'=>$sessionId, 'caseId'=>$caseId,
   'triggerIndex'=>$triggerId, 'delIndex'=>'1'));
$result = $client->__SoapCall('executeTrigger', $params);
if ($result->status_code != 0)
   print "Error: $result->message \n";
[/code]
Then set a cron job in your Linux server or a Windows scheduled task to periodically execute this file.

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]