Last active
March 2, 2022 17:01
-
-
Save BrianMRO/bb85966f7a97d45867cafa665a00748b to your computer and use it in GitHub Desktop.
Workflow - Blog Part 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using PX.Data; | |
using PX.Data.WorkflowAPI; | |
using PX.Objects.Common; | |
namespace Blog.CMMS | |
{ | |
using static PX.Data.WorkflowAPI.BoundedTo<CMMSWorkOrderEntry, CMMSWorkOrder>; | |
using static CMMSWorkOrder; | |
using State = Blog.CMMS.CMMSWorkOrder.Statuses; | |
public class CMMSWorkOrderEntry_Workflow : PXGraphExtension<CMMSWorkOrderEntry> | |
{ | |
public static bool IsActive() => | |
Common.FeatureInstalled<Common.CMMSFeaturesSet.main>(); | |
#region Define Constants | |
private const string | |
_actionRemoveHold = "Remove Hold", | |
_actionPutOnHold = "Hold"; | |
#endregion | |
#region Override Configure | |
public override void Configure(PXScreenConfiguration config) | |
{ | |
Configure(config.GetScreenConfigurationContext<CMMSWorkOrderEntry, CMMSWorkOrder>()); | |
} | |
#endregion | |
#region Configure the Workflow for This Screen | |
protected virtual void Configure(WorkflowContext<CMMSWorkOrderEntry, CMMSWorkOrder> context) | |
{ | |
#region Categories | |
var processingCategory = CommonActionCategories.Get(context).Processing; | |
#endregion | |
#region Actions | |
var removeHold = context.ActionDefinitions | |
.CreateNew(_actionRemoveHold, a => a | |
.WithCategory(processingCategory) | |
.PlaceAfter(g => g.Last) | |
); | |
var putOnHold = context.ActionDefinitions | |
.CreateNew(_actionPutOnHold, a => a | |
.WithCategory(processingCategory) | |
.PlaceAfter(removeHold) | |
); | |
#endregion | |
#region Configure the Screen | |
context.AddScreenConfigurationFor(screen => | |
{ | |
#region Define the Default Workflow | |
screen | |
.StateIdentifierIs<status>() | |
.AddDefaultFlow(flow => flow | |
.WithFlowStates(states => | |
{ | |
// Add Initial State | |
states.Add(State.InitialState, flowState => flowState.IsInitial(g => g.initializeState)); | |
// Add Normal States | |
states.Add<State.hold>(flowState => flowState | |
.WithActions(actions => | |
{ | |
actions.Add(removeHold, a => a.IsDuplicatedInToolbar()); | |
}) | |
.WithFieldStates(fields => | |
{ | |
fields.AddAllFields<CMMSWorkOrder>(); | |
fields.AddField<hold>(c => c.IsHidden()); | |
})); | |
states.Add<State.open>(flowState => flowState | |
.WithActions(actions => | |
{ | |
actions.Add(putOnHold); | |
actions.Add(g => g.schedule); | |
}) | |
.WithFieldStates(fields => | |
{ | |
fields.AddAllFields<CMMSWorkOrder>(); | |
fields.AddField<hold>(c => c.IsHidden()); | |
})); | |
states.Add<State.complete>(flowState => flowState | |
.WithFieldStates(fields => | |
{ | |
fields.AddAllFields<CMMSWorkOrder>(); | |
fields.AddField<hold>(c => c.IsHidden()); | |
})); | |
}) | |
.WithTransitions(transitions => | |
{ | |
transitions.AddGroupFrom(State.InitialState, ts => | |
{ | |
ts.Add(t => t | |
.To<State.hold>() | |
.IsTriggeredOn(g => g.initializeState)); | |
}); | |
transitions.Add(transition => transition | |
.From<State.hold>() | |
.To<State.open>() | |
.IsTriggeredOn(removeHold) | |
.WithFieldAssignments(fas => fas.Add<hold>(false)) | |
); | |
transitions.Add(transition => transition | |
.From<State.open>() | |
.To<State.hold>() | |
.IsTriggeredOn(putOnHold) | |
.WithFieldAssignments(fas => fas.Add<hold>(true)) | |
); | |
})); | |
#endregion | |
#region Add Actions to the Menus | |
screen | |
.WithActions(action => | |
{ | |
action.Add(removeHold); | |
action.Add(putOnHold); | |
action.Add(g => g.schedule, a => a | |
.WithCategory(processingCategory) | |
); | |
}); | |
#endregion | |
return screen; | |
}); | |
#endregion | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment