Change case status

In order to change a case's status, you will need to:

  1. Get the CaseTransitions for the CaseType of the case you want to transition
  2. Find the CaseTransition you want to apply
  3. If present, complete the values for the CaseForm attached to the CaseTransition
  4. Apply the CaseTransition to the case

Fetching the transitions

Use the CaseTransitionManager to retrieve all the transitions for the CaseType you want.

<?php

/** @var \Jadu\Quantum\ServiceApiClient\Manager\CaseTransitionManager $caseTransitionManager */
$caseTransitionManager = $container->get('quantum_service_api_client.manager.case_transition');
$transitions = $caseTransitionManager->getAllForCaseType('case-type-name');

You can then iterate over the array of transitions to find the one you want:

<?php

$transitions = $caseTransitionManager->getAllForCaseType('case-type-name');

foreach ($transitions as $transition) {
    print $transition->getName() . PHP_EOL;
}

Some transitions will require a CaseForm to be completed in order for them to be applied. You can retrieve the form from the transition if it has one:

<?php

if ($transition->hasCaseForm()) {
    $caseForm = $transition->getCaseForm();
}

Using the information in the CaseForm that is returned, you can now build up an array of values to use to apply the transition. Each CaseFormField has a unique name, you should use these as the key to each entry in the values array.

More information about CaseForms

<?php

$values = [];
foreach ($caseForm->getFields() as $formField) {
    $values[$formField->getName()] = 'VALUE';
}

Once you have your values array, you can apply the transition to the case:

<?php

$case = $caseManager->applyTransition($caseReference, $transition, $values);

Transitions can only be applied to a case when it has a CaseStatus that the transition is able to move the case from. If the transition is not able to be applied to the case in it's current status, nothing will happen to the case.

You can check the status of the case in the object returned from CaseManager::applyTransition.

results matching ""

    No results matching ""