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 keyangl
#813835
Hi there,

What is the REST API endpoint to call to claim a case where i used Self Service Value Based Assignment?

I've search the docs and it only mentions how to get Unassigned cases but not how to claim them, and a note saying:
Note: In order to claim a case, the logged-in user must either be assigned as a user or an ad hoc user to the case's current task

Doesn't really tell me how to claim it.
By keyangl
#813864
Thank you! I can claim a case now.
However it return a 400 instead of a 200 even if it claims, weird.
I need to tell whether the claim is a success or not to display a correct result to the user
User avatar
By amosbatto
#813877
The Light endpoints are deprecated and they aren't going to be fixed. I have created a new REST endpoint that you can use in my extraRest plugin:
(39 KiB) Downloaded 263 times
Go to Admin > Plugins > Plugin Manager and click on "Import". After importing the extraRest-1.tar file, then enable the plugin.

Here is the endpoint:
POST http://{domain-or-ip}/api/1.0/workflow/extrarest/case/{app_uid}/claim

POST parameters:
parameterDescription
del_indexOptional. The delegation index of the task to claim. Only needs to be included if there are multiple open tasks in the case.
usr_uidOptional. Unique ID of the user to assign to case. Only include if the logged-in user is a process supervisor assigning another user.
Response:
None if successful.

Examples:
Code: Select all
        //assigning logged-in user to a Self Service Task where there is only one open task in case:
        $caseId = '2554682895ac25995666e24055342045';
    $url = "/api/1.0/workflow/extrarest/case/$caseId/claim";
    $aVars = array();
    $oRet = pmRestRequest("POST", $url, $aVars, $oToken->access_token);

        //assigning logged-in user to a Self Service Task where there are 2 open tasks in case:
        $caseId = '2554682895ac25995666e24055342045';
    $url = "/api/1.0/workflow/extrarest/case/$caseId/claim";
    $aVars = array(
             'del_index' => 3
        );
    $oRet = pmRestRequest("POST", $url, $aVars, $oToken->access_token);

        //assigning another user to Self Service Task when logged-in user is a Process Supervisor:
    $caseId = '2554682895ac25995666e24055342045';
    $url = "/api/1.0/workflow/extrarest/case/$caseId/claim";
    $aVars = array(
      'del_index' => 2,  
      'usr_uid'   => '10654575559caec5e953104064429578' //unique ID of user to assign to task
    );
    $oRet = pmRestRequest("POST", $url, $aVars, $oToken->access_token); 
Here is the code of the endpoint, in case you want to modify it:
Code: Select all
    /**
     * Claim a case for the logged-in user where a task is unassigned because the task 
     * is Self Service or Self Service Value Based Assignment.
     * 
     * @url POST /case/:app_uid/claim
     * @access protected
     *
     * @param string $app_uid Case unique ID. {@from path}{@min 1}{@max 32}
     * @param int $del_index  Optional. The delegation index of the task to claim. 
     *  Only include if there are multiple open tasks in the case. {@from body}
     * @param string $usr_uid Optional. Unique ID of the user to assign to case. 
     *  Only include if the logged-in user is a process supervisor assigning another user {@from body}
     */
    public function postClaimCase($app_uid, $del_index = null, $usr_uid = null)
    {
        try {
            $loggedUserId = $this->getUserId();
            $oCase = new \Cases();
            
            if (empty($del_index)) {
               $del_index = $oCase->getCurrentDelegation($app_uid, '', true);
            }

            $oAppDel = new \AppDelegation();
            $aDelegation = $oAppDel->load($app_uid, $del_index);

            if ($aDelegation['USR_UID'] != '') {
                throw new \Exception("The task is already assigned to user with ID '{$aDelegation['USR_UID']}'."); 
            }
            
            if (empty($usr_uid) or $loggedUserId == $usr_uid) {
                $userIdToAssign = $loggedUserId;
            } 
            else {
                //check whether the user exists and has the PM_SUPERVISOR permission in role.
                $rbac = \RBAC::getSingleton();
                $rbac->initRBAC();
            
                if ($rbac->verifyUserId($usr_uid) != 1) {
                    throw new \Exception("User with ID '$usr_uid' does not exist.");
                }
            
                if ($this->userCanAccess('PM_SUPERVISOR') == 0) {
                    throw new \Exception("Logged-in user lacks the PM_SUPERVISOR permission in role.");
                }
                
                //check if logged-in user is assigned as a process supervisor to the process
                $oSuper = new \ProcessMaker\BusinessModel\ProcessSupervisor();
                $aSupervisorList = $oSuper->getProcessSupervisors($aDelegation['PRO_UID'], 'ASSIGNED');
                
                if (!isset($aSupervisorList['data']) or !is_array($aSupervisorList['data'])) {
                    throw new \Exception("Unable to retrieve list of supervisors for process.");
                }
                $isSuperForProcess = false;
                
                foreach ($aSupervisorList['data'] as $aSupervisorInfo) {
                    if ($aSupervisorInfo['usr_uid'] == $loggedUserId) {
                        $isSuperForProcess = true;
                        break;
                    }
                }
                
                if ($isSuperForProcess === false) {
                    throw new \Exception("User '$loggedUserId' must be assigned as a Supervisor for process '".
                       $aDelegation['PRO_UID']."'.");
                }       
                $userIdToAssign = $usr_uid;
            }
            
            return $oCase->setCatchUser($app_uid, $del_index, $userIdToAssign);
              
        } catch (\Exception $e) {
            throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
        }
    } 
By keyangl
#813878
Wow thank you so much.
However when i click on Enable in the plugin manager i get errors:
CapturePM4.PNG
CapturePM4.PNG (21.04 KiB) Viewed 4299 times
Got this error:
Code: Select all
<b>Fatal error</b>:  Can't use function return value in write context in <b>/usr/local/itapps/www/html/processmaker/workflow/engine/plugins/extraRest/src/Services/Api/ExtraRest/Extra.php</b> on line <b>242</b>
Maybe this may help you:
PHP 5.4
PM 3.0.1.7-community

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

Get an instant solution to move emails to MBOX for[…]