Skip to content

Instantly share code, notes, and snippets.

@BrianMRO
Created February 28, 2022 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianMRO/70f8e73bdeabe8353a07dad25ca766bd to your computer and use it in GitHub Desktop.
Save BrianMRO/70f8e73bdeabe8353a07dad25ca766bd to your computer and use it in GitHub Desktop.
Workflow - Blog Part 2
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 =>
{
return flow
.WithFlowStates(flowStates =>
{
// Add Initial State
flowStates.Add(State.InitialState, flowState => flowState.IsInitial(g => g.initializeState));
// Add Normal States
flowStates.Add<State.hold>();
flowStates.Add<State.open>();
flowStates.Add<State.complete>();
})
.WithTransitions(transitions =>
{
// Add the Transition Group and Transition the Initial State to Hold
transitions.AddGroupFrom(State.InitialState, ts =>
{
ts.Add(t => t
.To<State.hold>()
.IsTriggeredOn(g => g.initializeState)
);
});
});
});
#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