Skip to main content
Solved

How to customize of the default Shipment workflow via Workflow API and enable field SOShipment.shipVia in status Confirmed?


Forum|alt.badge.img

Hello everyone, asking for assistance

I need to customize behavior of the Shipment screen in status Confirmed (Acumatica 2022R2):

  1. I need to disable action correctShipmentAction
  2. I need to enable field SOShipment.shipVia

​​​​By default entire screen is disabled in status Confirmed, except ShipmentNbr field

Here’s my code:

            void EnableSomeFields(FieldState.IContainerFillerFields states)
            {
                states.AddField<SOShipment.shipVia>();
            }


              context.UpdateScreenConfigurationFor(config => config
                    .WithActions(actions => {
                        actions.Update(
                        action => action.correctShipmentAction, (ActionDefinition.ConfiguratorAction actionConfiguration) =>
                                        actionConfiguration.IsDisabledWhen(conditions.ShipmentIsInConfirmedStatus));
                    })
                    .UpdateDefaultFlow(flow => {
                        return flow.WithFlowStates(states => {
                            states.Update(State.Confirmed, state =>
                            {
                                return state.WithFieldStates(EnableSomeFields);
                            });
                        });
                    })
                );

Portion that makes action disabled works

Portion that makes fields enabled doesn’t work

 

Will appreciate your help

 

Regards,

Andrey

Best answer by abaranovhs

 So, finally got this to work.

To make Shipment fields enabled in status Confirmed I had to add two overrides:

  1. Override in graph RowSelected event
  2. Update workflow step

I.e. I guess Acumatica starts from applying logic of the Base graph, then applies logic of the Graph Extension, then logic of the Base workflow, and then logic of the Workflow Extension.

 

Also found useful page describing how field states are 

https://help.acumatica.com/(W(203))/Help?ScreenId=ShowWiki&pageid=0390a164-104e-492a-b45b-62359e389856
 

 

Here’s complete code:

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.Serialization;
using System.Text;
using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Data.WorkflowAPI;
using PX.Common;
using PX.Objects.AR;
using PX.Objects.CM;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.EP;
using PX.Objects.GL;
using PX.Objects.IN;
using PX.SM;
using PX.Objects.IN.Overrides.INDocumentRelease;
using POLineType = PX.Objects.PO.POLineType;
using POReceiptLine = PX.Objects.PO.POReceiptLine;
using PX.CarrierService;
using PX.Data.DependencyInjection;
using PX.LicensePolicy;
using PX.Objects.SO.Services;
using PX.Objects.PO;
using PX.Objects.AR.MigrationMode;
using PX.Objects.Common;
using PX.Objects.Common.Discount;
using PX.Objects.Common.Extensions;
using PX.Common.Collection;
using PX.Objects.SO.GraphExtensions.CarrierRates;
using PX.Objects.SO.GraphExtensions.SOShipmentEntryExt;
using PX.Api;
using LocationStatus = PX.Objects.IN.Overrides.INDocumentRelease.LocationStatus;
using ShipmentActions = PX.Objects.SO.SOShipmentEntryActionsAttribute;
using PdfSharp.Pdf.IO;
using PX.Objects.IN.Attributes;
using PX.Objects;
using PX.Objects.SO;

namespace PX.Objects.SO
{
  using static BoundedTo<SOShipmentEntry, SOShipment>;
  using State = SOShipmentStatus;

  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers

    protected virtual void SOShipment_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {

        SOShipment row = e.Row as SOShipment;

        if (row != null)
        {
          if (row.Status == SOShipmentStatus.Confirmed)
          {
            Base.Document.Cache.AllowUpdate = true;

            PXUIFieldAttribute.SetEnabled<SOShipment.shipVia>(cache, row, true);
            PXUIFieldAttribute.SetEnabled<SOShipment.siteID>(cache, row, true);
            PXUIFieldAttribute.SetEnabled<SOShipment.curyFreightCost>(cache, row, true);

          }
        }  
    }
    #endregion Event Handlers
  }

  #region Workflow Customization

  public class SOShipmentEntry_ExtWorkflow : PXGraphExtension<SOShipmentEntry_Workflow, SOShipmentEntry>
  {
    public static bool IsActive() => true;

    public override void Configure(PXScreenConfiguration config)
    {
        ConfigureNewWorkflow(config.GetScreenConfigurationContext<SOShipmentEntry, SOShipment>());
    }

    protected virtual void ConfigureNewWorkflow(WorkflowContext<SOShipmentEntry, SOShipment> context)
    {
        Condition Bql<T>() where T : IBqlUnary, new() => context.Conditions.FromBql<T>();

        var conditions = new
        {
            ShipmentIsInConfirmedStatus = Bql<Where<SOShipment.status, Equal<SOShipmentStatus.confirmed>>>()

        }.AutoNameConditions();

        context.UpdateScreenConfigurationFor(screen =>
        {
            return screen
                .WithActions(actions =>
                {
                    actions.Update(
                    action => action.correctShipmentAction, (ActionDefinition.ConfiguratorAction actionConfiguration) =>
                        actionConfiguration.IsDisabledWhen(conditions.ShipmentIsInConfirmedStatus));
                })
                .UpdateDefaultFlow(flow =>
                {
                    return flow
                        .WithFlowStates(states =>
                            states.Update<SOShipmentStatus.confirmed>(flowState =>
                            flowState
                            .WithFieldStates(containerAdjuster => {
                                containerAdjuster.AddField<SOShipment.shipVia>();
                                containerAdjuster.AddField<SOShipment.siteID>();
                                containerAdjuster.AddField<SOShipment.curyFreightCost>();
                            })
                        ));
                });
         });
     }
   }

  #endregion Workflow Customization            

}

 

View original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img
  • Jr Varsity III
  • 15 replies
  • January 26, 2024

@abaranovhs  Have you tried using the workflow functionality in a customization package?  I have enabled fields that would typically be locked down through this method before.  The other alternative would be following something like this where it is always enabled, then using workflow to better control when it is enabled based on status:

namespace PX.Objects.SO
{
  public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
    {
        protected virtual void SOShipment_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
        {
            InvokeBaseHandler?.Invoke(cache, e);
            SOShipment row = e.Row as SOShipment;
            if (row != null)
            {
                Base.Document.Cache.AllowUpdate = true;

                PXUIFieldAttribute.SetEnabled<SOShipmentExt.usrCustomField>(cache, row, true);
            }
        }
    }
}

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 16 replies
  • January 26, 2024

Hello,

Yes, I tried, it did not work.

Here’s I’m providing screenshot of the SalesDemo Acumatica showing shipment in status Confirmed and the customization with your suggested code applied.

 

My understanding is that at least in Acumatica 22R2 which I am on, it is no longer enough to have this in RowSelected event.

I also need to override default workflow via code or via customization project editor to manage state of the fields.

I want to do this via code, so this was the question - how do I write this code properly. I could not find an good example explaining how to override existing workflow and make field editable in a certain status in T270_WorkflowAPI documentation.


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 16 replies
  • Answer
  • January 26, 2024

 So, finally got this to work.

To make Shipment fields enabled in status Confirmed I had to add two overrides:

  1. Override in graph RowSelected event
  2. Update workflow step

I.e. I guess Acumatica starts from applying logic of the Base graph, then applies logic of the Graph Extension, then logic of the Base workflow, and then logic of the Workflow Extension.

 

Also found useful page describing how field states are 

https://help.acumatica.com/(W(203))/Help?ScreenId=ShowWiki&pageid=0390a164-104e-492a-b45b-62359e389856
 

 

Here’s complete code:

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.Serialization;
using System.Text;
using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Data.WorkflowAPI;
using PX.Common;
using PX.Objects.AR;
using PX.Objects.CM;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.EP;
using PX.Objects.GL;
using PX.Objects.IN;
using PX.SM;
using PX.Objects.IN.Overrides.INDocumentRelease;
using POLineType = PX.Objects.PO.POLineType;
using POReceiptLine = PX.Objects.PO.POReceiptLine;
using PX.CarrierService;
using PX.Data.DependencyInjection;
using PX.LicensePolicy;
using PX.Objects.SO.Services;
using PX.Objects.PO;
using PX.Objects.AR.MigrationMode;
using PX.Objects.Common;
using PX.Objects.Common.Discount;
using PX.Objects.Common.Extensions;
using PX.Common.Collection;
using PX.Objects.SO.GraphExtensions.CarrierRates;
using PX.Objects.SO.GraphExtensions.SOShipmentEntryExt;
using PX.Api;
using LocationStatus = PX.Objects.IN.Overrides.INDocumentRelease.LocationStatus;
using ShipmentActions = PX.Objects.SO.SOShipmentEntryActionsAttribute;
using PdfSharp.Pdf.IO;
using PX.Objects.IN.Attributes;
using PX.Objects;
using PX.Objects.SO;

namespace PX.Objects.SO
{
  using static BoundedTo<SOShipmentEntry, SOShipment>;
  using State = SOShipmentStatus;

  public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
  {
    #region Event Handlers

    protected virtual void SOShipment_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {

        SOShipment row = e.Row as SOShipment;

        if (row != null)
        {
          if (row.Status == SOShipmentStatus.Confirmed)
          {
            Base.Document.Cache.AllowUpdate = true;

            PXUIFieldAttribute.SetEnabled<SOShipment.shipVia>(cache, row, true);
            PXUIFieldAttribute.SetEnabled<SOShipment.siteID>(cache, row, true);
            PXUIFieldAttribute.SetEnabled<SOShipment.curyFreightCost>(cache, row, true);

          }
        }  
    }
    #endregion Event Handlers
  }

  #region Workflow Customization

  public class SOShipmentEntry_ExtWorkflow : PXGraphExtension<SOShipmentEntry_Workflow, SOShipmentEntry>
  {
    public static bool IsActive() => true;

    public override void Configure(PXScreenConfiguration config)
    {
        ConfigureNewWorkflow(config.GetScreenConfigurationContext<SOShipmentEntry, SOShipment>());
    }

    protected virtual void ConfigureNewWorkflow(WorkflowContext<SOShipmentEntry, SOShipment> context)
    {
        Condition Bql<T>() where T : IBqlUnary, new() => context.Conditions.FromBql<T>();

        var conditions = new
        {
            ShipmentIsInConfirmedStatus = Bql<Where<SOShipment.status, Equal<SOShipmentStatus.confirmed>>>()

        }.AutoNameConditions();

        context.UpdateScreenConfigurationFor(screen =>
        {
            return screen
                .WithActions(actions =>
                {
                    actions.Update(
                    action => action.correctShipmentAction, (ActionDefinition.ConfiguratorAction actionConfiguration) =>
                        actionConfiguration.IsDisabledWhen(conditions.ShipmentIsInConfirmedStatus));
                })
                .UpdateDefaultFlow(flow =>
                {
                    return flow
                        .WithFlowStates(states =>
                            states.Update<SOShipmentStatus.confirmed>(flowState =>
                            flowState
                            .WithFieldStates(containerAdjuster => {
                                containerAdjuster.AddField<SOShipment.shipVia>();
                                containerAdjuster.AddField<SOShipment.siteID>();
                                containerAdjuster.AddField<SOShipment.curyFreightCost>();
                            })
                        ));
                });
         });
     }
   }

  #endregion Workflow Customization            

}

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2754 replies
  • January 27, 2024

Thank you for sharing your solution with the community @abaranovhs!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings