Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By adijadhav
#789698
Hii
I am generating case using script task, where i fetched some data from database based on Database condition i need to create case.
I need urgent help on that. here i am provide the above please fix this issues.
I am executing script using timercrop.php.
Code: Select all
$db="60607910158b55173f0ab52027795788";
$rent_paymentid="30197143558ae849a59b648050874163";
$APP_UID=@@APPLICATION;
$current_date=getCurrentDate();
$property_status="Active";
$property_ownership="Rented";
$select = "select count(Property_id) as totalcount from Properties_master";

$count = executeQuery($select,$db);
if (is_array($result) and count($result) > 0)
	$count= $result[1]['totalcount'];

$user=@@USER_LOGGED;
$current_date=getCurrentDate();
for($i=1;$i<=$count;$i++) {
 	$select_data= "select date(next_payment_date), previous_payment_status, previous_payment_not_acceptance_count,
 	    escalation_percentage, escalation_Date,rent_amount, rent_frequency 
 	    from Properties_master 
 	    where property_status='$property_status' and property_ownership='$property_ownership' Order by Property_id Desc";
	
	$result=executeQuery($select_data,$db);
	if (is_array($result) and count($result) > 0)
		$next_payment_date= $result[$i]['next_payment_date'];
	
	$next_payment_date=date('Y-m-d', strtotime("$next_payment_date"));
	$previous_payment_status = $result[$i]['previous_payment_status'];
	$previous_payment_not_acceptance_count = $result[$i]['previous_payment_not_acceptance_count'];
	$escalation_percentage = $result[$i]['escalation_percentage'];
	$escalation_Date = $result[$i]['escalation_Date'];
	$rent_amount = $result[$i]['rent_amount'];
	$rent_frequency = $result[$i]['rent_frequency'];
		
	/*
	if ($escalation_percentage != NULL && strtotime($escalation_Date) == strtotime($current_date)) {
		$escalation_percentage=$escalation_percentage/100;
		$escalation_percentage=$escalation_percentage*$rent_amount;
		$rent_amount=$rent_amount+$escalation_percentage;	
	}*/
	
	if (strtotime($current_date) == strtotime($next_payment_date) && $previous_payment_status=="Accepted" && 
		$previous_payment_not_acceptance_count=="0")
	{	
		$newCaseId = PMFNewCase( @@PROCESS, $user, $rent_paymentid,
			array("expected_rent_payment_date"=>"$next_payment_date") );
	
		if ($newCaseId) {	
	   		executeQuery("UPDATE APPLICATION SET APP_STATUS='TO_DO' WHERE APP_UID='$newCaseId'");
	   	}
	}
	else {
		executeQuery("delete from app_cache_view where APP_UID='$APP_UID' AND APP_STATUS='DRAFT'");
		die();
	}
}	
User avatar
By amosbatto
#789711
I edited your code to clean up the spacing so it is more readable. I don't see any obvious problems in the code, but there are many things that I can't tell from seeing your code, like the structure of your database. You should run the code first as a trigger in a normal task so you can see the output in the debugger and check to see whether @@__ERROR__ was created with an error message.

Keep in mind that in script tasks, @@USER_LOGGED is set to the last user who worked on the case, which can be unpredictable if you have multiple threads in your process so there are parallel tasks to your script task. If you want the current logged-in user, then use:
$user = $_SESSION['USER_LOGGED'];
Make sure that the current user is also assigned to the initial task which is specified by $rent_paymentid.

There is no reason to include the die() at the end, unless you want to stop your process at that point. Generally the best strategy is to use die() when debugging and throw new Exception("my error message") when running in production.
By adijadhav
#789719
Hiii amosbatto,
Thanks for your guidance. But still having the same problem. I used above mentioned trigger is normal task where i assigned this trigger after task
it generates the cases that wanted to create based on database date match.
Like here i x date from database and match this date with current date and another 2 also from DB y and z if those conditions are satisfy then only i need to generate case using timereventcron. but it fails to match the database condition. The database structure of mine is simple and i am using custom database not a PM database from which i fetch the value.

Thanks.
User avatar
By amosbatto
#789741
Script tasks cannot be the first task in a case. Is that your problem? Script tasks don't need timereventcron.php to execute. Are you executing the script task after an intermediate timer event?
By adijadhav
#789744
Dear amosbatto,
Yes my script Task is first Task. So is there another way to execute script to generate case based on DB values.
If timereventcron is not possible for that, then there should be another way to execute script if script is first task.
Thanks for your Valuable suggestion.

Thakns and Regards
Aditya r Jadhav
User avatar
By amosbatto
#789750
You can create an external script which uses the newCase() web service or the POST /case endpoint to start the new case. Then you can execute that script at defined times with cron in Linux/UNIX or as a Scheduled Tasks in Windows.

Another way to start new cases is to create a separate loop-around process with an intermediate timer event which executes endlessly like this:
LoopAroundProcessToStartCases.png
LoopAroundProcessToStartCases.png (9.68 KiB) Viewed 6814 times
Place your trigger code in the "Start Cases" script task and set the time interval in the intermediate timer event. Then, start a new case in this process and let the case run forever. In your trigger code you can check whether a new case should start or not, based on your database queries.
By adijadhav
#790145
Dear amosbotto,
When i run timereventcron.php is shows following things.
Code: Select all
Processing workspace: workflow
+--------------------------------------------------------------------------------------------------+
| > Creating the new case...
|     - OK case #2113 was created
| > Routing the case #2113...
|     - Failed: The row '' in table TASK doesn't exist!
|
| > Creating the new case...
|     - OK case #2114 was created
| > Routing the case #2114...
Finished 1 workspaces processed
Done!
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

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[…]