Solved

Enable the Locked field using WorkFlow Code

  • 7 February 2024
  • 13 replies
  • 93 views

Userlevel 3
Badge

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?

 

icon

Best answer by darylbowman 7 February 2024, 17:52

View original

13 replies

Userlevel 3
Badge

@Brian Stevens  @darylbowman Can you please help me with this?

Badge +11

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);
}

 

Userlevel 7
Badge +12

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 @darylbowman bit of code to allow the field to be edited 

Badge +11

...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.

Badge +11

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);
}
}

 

Userlevel 7
Badge +12

...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.

 

 @darylbowman You can do it like this so i have copied the RO Workflow and set it as Active I added the Location and made it editable on the Completed Status of the Normal Purchase Order as below

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.

Badge +11

Ah, ok. I think OP specifically asked for workflow code, which is why I was confused how you were doing it.

Userlevel 7
Badge +12

@darylbowman Sorry it was just a suggestion without code

Userlevel 3
Badge

@darylbowman Thanks a lot for sharing the sample code. I have tried for the Sales Order screen → Description field but seems like not working. Can you please review and help me where am I doing wrong?

 


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>();
});
});
});
});
});


});
}
}
}

 

Badge +11

In this portion (close to the end), do the following:

return state
.WithFieldStates(fields =>
{
fields.RemoveField<SOOrder.orderDesc>();
fields.AddField<SOOrder.orderDesc>();
});

 

Userlevel 3
Badge

No Luck @darylbowman  still same issue.

Badge +11

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.

Badge +11

@nsmith51 - Were you able to resolve this?

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved