API ProcessMaker behavior to start task

Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

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.
marcosfpa
Posts: 169
Joined: Sat Nov 21, 2015 8:28 am
Country: Brazil

API ProcessMaker behavior to start task

Unread postby marcosfpa » Wed Oct 11, 2017 4:55 pm

Hello, in my intranet I have created an interface to interact with the Processmaker task list using the APIs. I am able to list the tasks, pause, pause, etc ...
But there is one item I am not getting: pass to the processmaker via API that the task was started. In the processmaker is when we access the task via 2 clicks on it ...
Any idea?

amosbatto
Posts: 5322
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: API ProcessMaker behavior to start task

Unread postby amosbatto » Wed Oct 11, 2017 6:14 pm

When a task in a case is opened, nothing happens to the case until the first step (DynaForm, Input Document or Output Document) in the task is submitted. Then the APP_STATUS changes from 'TO_DO' to 'DRAFT'. If you want to cause that status change, then create a trigger with this code:

Code: Select all

$c = new Cases();
$aCaseInfo = $c->LoadCase(@@APPLICATION, @%INDEX);
$aCaseInfo['APP_STATUS'] = 'DRAFT';
$c->updateCase(@@APPLICATION, $aCaseInfo); 

Then execute this trigger with /cases/{app_uid}/execute-trigger/{tri_uid}
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

marcosfpa
Posts: 169
Joined: Sat Nov 21, 2015 8:28 am
Country: Brazil

Re: API ProcessMaker behavior to start task

Unread postby marcosfpa » Wed Oct 11, 2017 7:31 pm

But will I have to create a TRIGGER for each process?
It would be very laborious, I would like a more global or generic solution that would apply to all ...

amosbatto
Posts: 5322
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: API ProcessMaker behavior to start task

Unread postby amosbatto » Thu Oct 12, 2017 8:57 am

Well, you could create a custom REST endpoint with this code:

Code: Select all

$c = new Cases();
$aCaseInfo = $c->LoadCase($caseId, $delIndex);
$aCaseInfo['APP_STATUS'] = 'DRAFT';
$c->updateCase(@@APPLICATION, $aCaseInfo);


or you could first set the case variables @@caseId and @@delIndex in the case with REST POST cases/{app_uid}/variables and then call execute-trigger.
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

marcosfpa
Posts: 169
Joined: Sat Nov 21, 2015 8:28 am
Country: Brazil

Re: API ProcessMaker behavior to start task

Unread postby marcosfpa » Tue Oct 17, 2017 2:34 pm

I do not understand very well, should I create a plugin that creates a custom API, would it?

amosbatto
Posts: 5322
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: API ProcessMaker behavior to start task

Unread postby amosbatto » Wed Oct 18, 2017 1:09 am

marcosfpa wrote:I do not understand very well, should I create a plugin that creates a custom API, would it?

Let me try to explain better. One option is to create a custom REST endpoint with this code:

Code: Select all

$c = new Cases();
$aCaseInfo = $c->LoadCase($caseId, $delIndex);
$aCaseInfo['APP_STATUS'] = 'DRAFT';
$c->updateCase($caseId, $aCaseInfo);

Where $caseId and $delIndex are passed by your REST endpoint either as POST variables or as GET variables in the URL.

The second option is probably easier. Create a process which is only used to reset the status of cases which has a case which never closes:
looparoundProcess.png
looparoundProcess.png (6.66 KiB) Viewed 3 times


Then, add this trigger to the process:

Code: Select all

if (empty(@@caseId)) {
   throw new 
Exception("The caseId variable was not set!");
}

$c = new Cases();
$aCaseInfo $c->LoadCase(@@caseId, @@delIndex);
$aCaseInfo['APP_STATUS'] = 'DRAFT';
$c->updateCase(@@caseId$aCaseInfo);
 


Then start a case in this process and copy its case ID, which you can use forever in your script code.

When you want to change the status of a case from "TO_DO" to "DRAFT", then use a script like this:

Code: Select all

$permanentCaseId = 'XXXXXXXXXXXXXXXXXXXXXXX'; //set to the ID of the case that never closes

//set to the ID and delegation index of the case whose status should be changed:
$aVars = array(
   "caseId"    => '78484118955bbd5fc39e5c5072875367',                      
   
"delIndex"=> 2
);

//first set the case variables:
$url = "/api/1.0/workflow/cases/$permanentCaseId/variable";
$oRet = pmRestRequest("PUT", $url, $aVars, $oToken->access_token);
if ($oRet->status != 200) {
   throw new Exception("Error setting variables in case.");
}

//then execute the trigger:
$triggerId = '37823572555ba5891041136049273220';
$url = "/api/1.0/workflow/cases/$permanentCaseId/execute-trigger/$triggerId";
$oRet = pmRestRequest('PUT', $url, null, $oToken->access_token);
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)


Return to “Developing processes & programming”

Who is online

Users browsing this forum: No registered users and 2 guests