Workflow Actions: Configuration of Persisting Options
In the code of a graph, you can save the changes to the database by calling the
Persist method. When adding an action to a screen
configuration, you can configure whether and when the current changes in the cache
should be saved to the database—that is, when the system should invoke the
Persist method. This configuration can be defined by using
the values in the ActionPersistOptions enumerator of the
WithPersistOptions method. The
ActionPersistOptions enumerator provides the following
values:
- ActionPersistOptions.NoPersist: A new or existing entity will not be saved when the action is executed.
- ActionPersistOptions.Auto: A new or existing entity will be saved after the action is executed. However, a new entity will not be saved if the action is explicitly declared to be of the PXAutoAction type and this action is configured to be executed automatically by the workflow.
- ActionPersistOptions.PersistBeforeAction: A new entity will be saved before the action is executed. An existing entity will be saved after the action is executed.
Attention:
If the action being executed triggers a transition, then the
transition, by default, will cause the entity to be saved to the database. In this
case, specifying the
WithPersistOptions(ActionPersistOptions.NoPersist) method in
that action would have no effect. To prevent the transition from saving the entity
to the database, call the DoesNotPersist method in the
transition.
The following example shows an action from the workflow on the Opportunities (CR304000) form.
.WithActions(actions =>
{
actions.Add(g => g.Open, c => c
.WithForm(formOpen)
.WithFieldAssignments(fields =>
{
fields.Add<CROpportunity.resolution>(f => f.SetFromFormField(formOpen, ReasonFormField));
fields.Add<CROpportunity.stageID>(f => f.SetFromFormField(formOpen, StageFormField));
fields.Add<CROpportunity.isActive>(f => f.SetFromValue(true));
fields.Add<CROpportunity.closingDate>(f => f.SetFromValue(null));
})
.IsHiddenWhen(conditions.IsInNewState)
.WithPersistOptions(ActionPersistOptions.PersistBeforeAction)
.WithCategory(categoryProcessing)
.IsExposedToMobile(true)
.MassProcessingScreen<UpdateOpportunityMassProcess>());
If you need to save the changes of one entity on a form where this entity is not used, you need to override the Persist method of this form and manually save these changes of this custom entity. This might be useful, for example, if you need to save the changes of a custom entity on a predefined form. For more information, see Step 6: Overriding the PerformPersist Method.