Solved

21R2 (21.193.0119) - How to update "Configuration Entry" pop-up records through code (using Manufacturing Module)

  • 12 October 2021
  • 1 reply
  • 173 views

Userlevel 4
Badge

Hello Everyone,

We have a requirement where we are using Manufacturing module and trying to map options from "Configuration Entry" pop-up through code but while doing getting unexpected errors like: “Move Next” etc.

Sharing our requirement and sample code for your review and feedback, please find details below:

Requirement:

  • Created a Configuration ID on Configuration Maintenance screen
  • Used that record on Sales Order screen under Details tab.
  • Now on Sales Order Save action based on some custom condition we want to check include checkbox, then execute save action on pop-up and then execute FINISH button, available on pop-up.
  • As per below screenshot we want to mark Included checkbox true under OPTION tab for each feature: Pattern, Grove, Doors, Jamb through code.

 

Sample Code:

public class KNBCSOOrderEntryExt : PXGraphExtension<SOOrderEntry>
    {
        public static bool IsActive() { return true; }
        #region Persist Override
        public delegate void PersistDelegate();
        [PXOverride]
        public void Persist(PersistDelegate del)
        {
            del();
            //COLOR:RED | DIMENSION:24x36 | DRNHOLES:YES | DOOR:Solid Core
            ConfigurationEntry configGraph = PXGraph.CreateInstance<ConfigurationEntry>();
            foreach (SOLine line in Base.Transactions.Select())
            {
                foreach (AMConfigResultsOption option in PXSelectJoin<AMConfigResultsOption,
                                                            InnerJoin<AMConfiguration, On<AMConfiguration.configurationID, Equal<AMConfigResultsOption.configurationID>>>,
                                                            Where<AMConfiguration.inventoryID, Equal<Required<AMConfiguration.inventoryID>>>>
                                                            .Select(Base, line.InventoryID))
                {
                    configGraph.Options.Update(option); // causing Move Next Error
                    configGraph.Options.Current = option; // causing Move Next Error
                    if (configGraph.Options.Current != null)
                    {
                        configGraph.Options.Current.Included = true;
                        configGraph.Options.Update(configGraph.Options.Current);
                    }
                    //Skipped above code piece and tried below
                    option.Included = true;
                    configGraph.Options.Update(option); // causing Move Next Error
                }
            }
            configGraph.Actions.PressSave();
        }
        #endregion
    }

 

Can anyone suggest best possible way to achieve this please.

Thank you in advance !

icon

Best answer by vivekm 18 October 2021, 14:38

View original

1 reply

Userlevel 4
Badge

Hello Everyone,

We received inputs from Acumatica support team (special thanks to Nayan Mansinha) and is working as expected. Please find below additional details and code sample for reference:

 

One need to first load ConfigurationEntry graph with the right SOLine item and then work with it.  See example below that show how Results view is initialized.  Then required Options are Included based on CurrentFeature record.  Also note that

1) whole thing is part of single transaction scope and base Persist() is called first so that required configuration records are formed. 

2) Slots are used to avoid infinite loop that can occur as Finish() calls for saving of the graph.

 

using PX.Common;
using PX.Data;
using PX.Objects.AM;
using PX.Objects.AM.CacheExtensions;
using PX.Objects.AM.GraphExtensions;

namespace PX.Objects.SO
{
    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {
        public static bool IsActive() => true;

        #region Event Handlers
        public delegate void PersistDelegate();
        [PXOverride]
        public void Persist(PersistDelegate baseMethod)
        {
            if (PXContext.GetSlot<bool?>("configFinish") == true)
                return;

            try
            {
                PXContext.SetSlot<bool?>("configFinish", true);
                using (var txn = new PXTransactionScope())
                {
                    baseMethod();

                    var AMExtGraph = Base.GetExtension<SOOrderEntryAMExtension>();
                    ConfigurationEntry configGraph = PXGraph.CreateInstance<ConfigurationEntry>();

                    foreach (SOLine line in Base.Transactions.Select())
                    {
                        var soLineExt = PXCache<SOLine>.GetExtension<SOLineExt>(line);
                        if (!AMExtGraph.AllowConfigurations
                            || !soLineExt.IsConfigurable.GetValueOrDefault())
                        {
                            continue;
                        }

                        AMConfigurationResults configuration = AMExtGraph.ItemConfiguration.Select();
                        if (configuration != null)
                        {
                            configGraph.Results.Current = configGraph.Results.Search<AMConfigurationResults.configResultsID>
                                (configuration.ConfigResultsID);
                            configGraph.CurrentFeature.Current = configGraph.CurrentFeature.Select(1); //FeatureLineNbr  - do this as many feature for the item. e.g. AMDOORDH01 has 4 features

                            AMConfigResultsOption option1 = configGraph.Options.Search<AMConfigResultsOption.optionLineNbr>(1);
                            option1.Included = true;
                            configGraph.Options.Update(option1);

                            configGraph.CurrentFeature.Current = configGraph.CurrentFeature.Select(2);
                            AMConfigResultsOption option2 = configGraph.Options.Search<AMConfigResultsOption.optionLineNbr>(1);
                            option2.Included = true;
                            configGraph.Options.Update(option2);

                            configGraph.CurrentFeature.Current = configGraph.CurrentFeature.Select(3);
                            AMConfigResultsOption option3 = configGraph.Options.Search<AMConfigResultsOption.optionLineNbr>(1);
                            option3.Included = true;
                            configGraph.Options.Update(option3);

                            configGraph.CurrentFeature.Current = configGraph.CurrentFeature.Select(4);
                            AMConfigResultsOption option4 = configGraph.Options.Search<AMConfigResultsOption.optionLineNbr>(1);
                            option4.Included = true;
                            configGraph.Options.Update(option4);
                        }
                    }

                    if (configGraph.IsDirty)
                    {
                        configGraph.Finish.Press();
                    }

                    txn.Complete();
                }
            }
            finally
            {
                PXContext.SetSlot<bool?>("configFinish", false);
            }
        }


        #endregion
    }
}

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