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 pwaller24
#793207
I'm successfully creating a case using the New Case Impersonate API and assigning it to a user. The documentation for the API talks about running a trigger to set the status of the case to TO DO as it is create as DRAFT. When I attempt to execute the trigger the message back is:
Code: Select all
{
"error": {
"code": 400,
"message": "Bad Request: This case is assigned to another user"
}
}
Not sure how to proceed here as I want the process to assign the case to a specific user and then change the status to DO.
#793210
I assume that you assigned the new case to another user, so if you want to execute a trigger inside that new case, you need to use REST to login as that other user. Then call the execute-trigger endpoint as that other user.

However, this is problem if you don't know the password of the other user. What you can do is create a separate process which has the following trigger:
Code: Select all
if (isset(@@newCaseId) and !empty(@@newCaseId)) {
   $c = new Cases();
   $aCase = $c->loadCase(@@newCaseId, 1);
   $aCase['APP_STATUS'] = 'TO_DO';
   $c->updateCase($newCaseId, $aCase);
/*Add this code if using PM 3.2:
   //change the status of the case in the Home > Participated list:
   $aData = array(
      'APP_UID' => $aCase['APP_STATUS'];
      'USR_UID' => $aCase['CURRENT_USER_UID'];
      'DEL_INDEX' => $aCase['DEL_INDEX'],
      'APP_STATUS' => 'TO_DO';
   );
   $oListPartLast = new ListParticipatedLast();
   $oListPartLast->update($aData);
*/
  @@newCaseId = ""; //reset so empty for next time
}  
Then create a permanent case in that process with the same user that you use in your REST script. Don't ever finish the case so you can always use the same case over and over to execute the trigger. Run the case in debug mode so you can see the case ID found in the APPLICATION variable. Copy it down and use the case ID in your REST code.

Then in your rest script, first call the POST /cases endpoint to create the new case. Then call PUT /cases/{app_uid}/variable on your permanent case where you have the trigger. You can always use the same case to execute your trigger, as long as you never close the case. Set the variable newCaseId in your permanent case to the ID of the new case that was created with POST /case. Finally, call the /execute-trigger endpoint in your permanent permanent case to execute the trigger.

By the way, which version of PM are you using. I think in PM 3.2, this got fixed (or it was supposed to be fixed).
#793232
Bonifac wrote:Hi! I use the PM 3.2 and REST API. I would like to create the new cases in TO DO status. There is a status parameter in the POST /cases REST endpoint according to this documentation (http://wiki.processmaker.com/3.2/Trigge ... s_to_TO_DO), but i can't find it on the REST API wiki page. Should I use trigger?
The Dev team said they fixed this in PM 3.2, but they only fixed it for PMFNewCase(). I just checked the code. It only works for PMFNewCase(), but not for the POST /cases endpoint in PM 3.2. Your only option is to use the trigger code I gave above.
pwaller24 wrote:I am using Processmaker 3.1.3. I've tried to install 3.2 but having issues. The REST calls are being made outside of ProcessMaker.
You have to use the code i gave you in PM 3.1.3.
#793791
I have tried the code suggested above:

$c = new Cases();
$aCase = $c->loadCase(@@newCaseId, 1);
$aCase['APP_STATUS'] = 'TO_DO';
$c->updateCase($newCaseId, $aCase);

And it is not moving the Case from Draft to Inbox. I have added some dynaforms displaying data before and after the trigger is executed and for some reason it is not updating the Case. Is there any kind of return code from the updateCase call that can be looked at?
#793808
There is no return value for Cases::updateCase(). Post your REST code. Maybe you aren't sending the newCaseId variable correctly to the case. The APPLICATION.APP_STATUS and APP_CACHE_VIEW.APP_STATUS fields should change to 'TO_DO' in the database.

🚀 Tauchen Sie mit Immediate Alora AI in die Welt d[…]

Do you want a quick way to delete passwords from P[…]

Try the CloudMigration PST Converter to convert […]

In the rapidly evolving world of online sports be[…]