Change case status
In order to change a case's status, you will need to:
- Get the
CaseTransitionsfor theCaseTypeof the case you want to transition - Find the
CaseTransitionyou want to apply - If present, complete the values for the
CaseFormattached to theCaseTransition - Apply the
CaseTransitionto 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.