Hello Everyone,
Can you please help me with the sample source code to enable the field in the Sales Order screen when the Sales Order status is in COMPLETED status using WORKFLOWs from the code level?
Hello Everyone,
Can you please help me with the sample source code to enable the field in the Sales Order screen when the Sales Order status is in COMPLETED status using WORKFLOWs from the code level?
I don’t have time to convert it to Sales Orders right now, but this is to enable a custom field in Purchase Order workflow. This should get you close.
Extend the system workflow:
using static PX.Data.WorkflowAPI.BoundedTo<POOrderEntry, POOrder>;
public class POOrderEntry_WorkflowExt : PXGraphExtension<PX.Objects.PO.POOrderEntry_Workflow, POOrderEntry>
{
public override void Configure(PXScreenConfiguration config) =>
Configure(config.GetScreenConfigurationContext<POOrderEntry, POOrder>());
protected virtual void Configure(WorkflowContext<POOrderEntry, POOrder> context)
{
context.UpdateScreenConfigurationFor(screen =>
{
return screen
.WithFlows(flows =>
{
flows.Update<POOrderType.blanket>(flow =>
{
return flow
.WithFlowStates(states =>
{
states.Update<POOrderStatus.open>(state =>
{
return state
.WithFieldStates(fields =>
{
fields.AddField<POOrderExt.usrAckDate>();
});
});
});
});
});
});
}
}
In the regular graph extension (or it may work in the one above):
protected virtual void _(Events.RowSelected<POOrder> e)
{
POOrder row = e.Row;
if (row is null) return;
Base.Document.Cache.AllowUpdate = true;
Base.Transactions.Cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled<POOrderExt.usrAckDate>(e.Cache, row, true);
}
Is your field on the Sales Order itself or on the SOLine. You can copy the workflow and allow it to be edited and if it is on the line you will also need
...You can copy the workflow and allow it to be edited...
Not sure I’m following here. Pretty certain you need code either way. This example is for POOrder, not POLine, unless SOOrder is different somehow.
By chance, I happened to find more applicable code, but this is for SOLine:
public class SOOrderEntry_Workflow_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry_Workflow, SOOrderEntry>
{
public static bool IsActive() => false;
public override void Configure(PXScreenConfiguration config) =>
Configure(config.GetScreenConfigurationContext<SOOrderEntry, SOOrder>());
protected virtual void Configure(WorkflowContext<SOOrderEntry, SOOrder> context)
{
context.UpdateScreenConfigurationFor(screen =>
{
return screen
.WithFlows(flows =>
{
flows.Update<SOOrderTypeConstants.salesOrder>(flow =>
{
return flow
.WithFlowStates(states =>
{
states.Update<SOOrderStatus.open>(state =>
{
return state
.WithFieldStates(fields =>
{
fields.RemoveField<SOLine.unitCost>();
fields.AddField<SOLine.unitCost>();
});
});
});
});
});
});
}
}
public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{
public static bool IsActive() => true;
#region Event Handlers
protected virtual void _(Events.RowSelected<SOLine> e, PXRowSelected b)
{
SOLine row = e.Row;
if (row is null) return;
b?.Invoke(e.Cache, e.Args);
// Enable 'Unit Cost' field
Base.Document.Cache.AllowUpdate = true;
Base.Transactions.Cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled<SOLine.curyUnitCost>(e.Cache, row, true);
}
}
...You can copy the workflow and allow it to be edited...
Not sure I’m following here. Pretty certain you need code either way. This example is for POOrder, not POLine, unless SOOrder is different somehow.
Then if you go to a Completed PO of Type Normal the location is editable. I do the same for the PO Line in the workflow but you need to add the second sample of code like you provided.
Ah, ok. I think OP specifically asked for workflow code, which is why I was confused how you were doing it.
using PX.Data;
using PX.Objects.SO;
using PX.Data.WorkflowAPI;
namespace Test
{
using static PX.Data.WorkflowAPI.BoundedTo<SOOrderEntry, SOOrder>;
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry_Workflow, SOOrderEntry>
{
public static bool IsActive() => true;
protected virtual void _(Events.RowSelected<SOOrder> e)
{
SOOrder row = e.Row;
if (row is null) return;
Base.Document.Cache.AllowUpdate = true;
Base.Transactions.Cache.AllowUpdate = true;
PXUIFieldAttribute.SetEnabled<SOOrder.orderDesc>(e.Cache, row, true);
PXUIFieldAttribute.SetReadOnly<SOOrder.orderDesc>(e.Cache, row, false);
}
public override void Configure(PXScreenConfiguration config)
{
Configure(config.GetScreenConfigurationContext<SOOrderEntry, SOOrder>());
}
protected virtual void Configure(WorkflowContext<SOOrderEntry, SOOrder> context)
{
context.UpdateScreenConfigurationFor(screen =>
{
return screen
.WithFlows(flowStates =>
{
flowStates.Update<SOBehavior.sO>(flow =>
{
return flow
.WithFlowStates(states =>
{
states.Update<SOOrderStatus.completed>(state =>
{
return state
.WithFieldStates(fields =>
{
fields.AddField<SOOrder.orderDesc>();
});
});
});
});
});
});
}
}
}
In this portion (close to the end), do the following:
return state
.WithFieldStates(fields =>
{
fields.RemoveField<SOOrder.orderDesc>();
fields.AddField<SOOrder.orderDesc>();
});
No Luck
Are you certain the Document Type is ‘SO’ and the Status is ‘Completed’? It copied your code, added the one line I indicated, and published it and it works for me, for ‘SO’ types in ‘Completed’ status.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.