Workflow Actions: Persisting Options
In the code of a graph, you can save the changes to the database by calling the PXGraph.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 in the WithPersistOptions method by using the values of the ActionPersistOptions enumerator.
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.