To Assign Field Values Before and After a Transition is Performed

In workflow code, for a workflow state, you can specify a list of field assignments that will be performed when a document enters the state and when a document leaves the state.

To provide a list of fields whose values should be assigned when a document enters a state, use the flowState.WithOnEnterAssignments method when defining the state. The field assignments listed in the method are applied to the state for which the method was called.

To provide a list of fields whose values should be assigned to a state when a document leaves a state, use the flowState.WithOnLeaveAssignments method when defining the state. The field assignments listed in the method are applied to the state for which the method was called.

Example of using these methods is shown in the following code.

flowStates.Add<State.hold>(flowState =>
{
  return flowState
    .WithActions(actions => …);
    .WithOnEnterAssignments(fields => fields.Add<inclCustOpenOrders>(false));
    .WithOnLeaveAssignments(fields => fields.Add<inclCustOpenOrders>(true));
    ...
}

In the code above, the inclCustOpenOrders field is assigned false when the document state is changed to hold (after the transition to this state is completed), and the inclCustOpenOrders field is assigned true before the hold state is changed to some other state (before the transition is started).