Forums › Forums › OroPlatform › OroPlatform – Programming Questions › Workflow use same field in preconditions and conditions
This topic contains 10 replies, has 2 voices, and was last updated by Mike Kudelya 6 years, 10 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- April 27, 2017 at 4:31 pm #34371
I have following example workflow:
YAML12345678workflows:example:...transition_definitions:preconditions:@empty: $product.statusconditions:@not_empty: $product.statusThe transition has a form where the product.status is set.
It’s not possible to execute the transition after setting the product.status as it’s not allowed.Are the precoditions being also checked when executing a transition ?
- CreatorTopic
- AuthorReplies
- April 28, 2017 at 10:18 am #34372
Hi
As i understood you want to show a popup when entity product->status field is empty and set form field constraint to avoid enter empty values. If yes, please add the following code to your transition:
YAML1234options:required: trueconstraints:- NotBlank: ~Here is an example.
April 28, 2017 at 10:22 am #34373In my case the popup works and saves the value.
But the transition is not executed because after product save the precodition is not valid anymore, because the product has the status.
Part of code from Oro\Bundle\WorkflowBundle\Model\Transition
PHP12345public function isAllowed(WorkflowItem $workflowItem, Collection $errors = null){return $this->isPreConditionAllowed($workflowItem, $errors)&& $this->isConditionAllowed($workflowItem, $errors);}The transition should only be possible if the value is empty. The form should be shown only if product status has no value.
Here is a part from the docs:
There are two types of conditions – preconditions and actually transit conditions. Preconditions is used to check whether transition should be allowed to start, and actual conditions used to check whether transition can be done. Good example of usage is transition forms: preconditions are restrictions to show button that open transition form dialog, and actual transitions are used to validate form content after submitting.
So i supposed the preconditions are being only validated to check if a transition is valid.
April 28, 2017 at 2:45 pm #34374As it’s written in the docs, the preconditions are used to check if the transition should be allowed to start. Why are the precondition also checked when executing the transition,after it was already started ?
May 4, 2017 at 2:45 am #34375Why are the precondition also checked when executing the transition, after it was already started ?
I think it has been done to avoid manually sending the http request to the server (without pressing the button).
Your transition is not executed because when you execute the ‘conditions’ node, $product.status is still empty because the ‘conditions’ node is checked before saving.
$product.status – checking the product entity status field.
$status – checking the form status field.Try to check your transition using the following approach:
PHP1234preconditions: # if lead.status = "new"'@empty': $product.statusconditions:'@not_empty': $statusDo not forget to add a status attribute.
May 4, 2017 at 3:09 am #34376Hi Mike,
as i already described before, the preCondition is not valid when executing the transition. The condition is ok, because the transition object is already saved , when the transition is executed.
Here some debugging info:
YAML12345678preconditions:'@or':- '@empty': $product.attributeSet- '@empty': $product.typeconditions:'@and':- '@not_empty': $product.attributeSet- '@not_empty': $product.type
May 4, 2017 at 5:17 am #34377The missing images :
May 4, 2017 at 12:14 pm #34378Hi Mike,
the case you’ve described, also won’t work. Because of the precondition. In isAllowed method of the Transition model preconditions are also checked , before finishing the transition.
May 8, 2017 at 2:39 am #34379Hi
Can you describe start values of your fields, which participate in the work, detailed use case, how should work your fields? (popup fields types, when the step button/popup must be shown, what condition must be executed when you click to Save button in your popup)
May 8, 2017 at 2:46 am #34380Hi
it should work as follows:
– the transition button should be enabled if $product->status is null (precondition)
– the popup form has only one dropdown with the status values
– after clicking the ‘save’ in popup product status is saved
– executing transition if $product->status is not null (condition)May 9, 2017 at 2:26 am #34381Hi
Please try to use this variant.
PHP123456789101112131415161718192021transitions:first_transition:form_options:attribute_fields:......form_init:- '@assign_value':attribute: $.data.is_form_shownvalue: 1transition_definitions:first_definition:preconditions:'@or':- '@eq': [$.data.is_form_shown, 1]- '@empty':message: 'pre'parameters: $product.statusconditions:'@not_empty':message: 'con'parameters: $product.status - AuthorReplies
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.