Skip to main content

I have created a button on the Process Order page 

What I want is that when I click the Demo Processing button, the Processing dialog should be displayed. To be able to control whether the insert Order was successful or not. Function GenerateNewLineItems will work on insert item in OrderLine.

function GenerateNewLineItems.

using System;
using System.Collections;
using System.Collections.Generic;
using PX.CloudServices.DAC;
using PX.Data;
using PX.Objects.CN.Subcontracts.AP.CacheExtensions;
using PX.Objects.SO;

public class SOCreateShipment_Extension : PXGraphExtension<PX.Objects.SO.SOCreateShipment>
{
    public PXAction<SOOrderFilter> DemoProcessing;
    PXButton(CommitChanges = true)]
    bPXUIField(DisplayName = "Demo Processing")]
    protected void demoProcessing()
    {
        SOOrderFilter filter = Base.Filter.Current;
        if (filter == null)
        {
            throw new PXException("Filter cannot be null");
        }

        PXLongOperation.StartOperation(Base, () =>
        {
            try
            {
                foreach (SOOrder order in PXSelect<SOOrder>.Select(Base))
                {
                    var filePath = PXCache<SOOrderFilter>.GetExtension<SOOrderFilterExt>(filter).UsrNextSchShipDate;
                    if (filePath != null)
                    {
                        int shipOnMonthOffset = 3;

                        SOOrder parentOrder = PXSelect<SOOrder, Where<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>.Select(Base, order.OrderNbr);

                        if (parentOrder != null)
                        {
                            GenerateNewLineItems(parentOrder, filePath, shipOnMonthOffset);
                            PXProcessing<SOOrderFilter>.SetProcessed();
                        }
                        else
                        {
                            PXProcessing<SOOrderFilter>.SetError(new PXException("The order has not been selected from the list"));
                        }
                    }
                    else
                    {
                        PXProcessing<SOOrderFilter>.SetError(new PXException("There is no Next Sch Ship Date yet"));
                    }
                }
            }
            catch (Exception ex)
            {
                PXTrace.WriteError(ex);
                throw new PXOperationCompletedException("Error in Demo Processing: " + ex.Message);
            }
        });
    }

    private void GenerateNewLineItems(SOOrder parentOrder, DateTime? nextSchShipDate, int shipOnMonthOffset)
    {
        using (PXTransactionScope ts = new PXTransactionScope())
        {
            SOOrderEntry orderEntryGraph = PXGraph.CreateInstance<SOOrderEntry>();
            orderEntryGraph.Document.Current = orderEntryGraph.Document.Search<SOOrder.orderNbr>(parentOrder.OrderNbr, parentOrder.OrderType);
            var duplicatedBranchesAndInventories = new HashSet<(int?, int?)>();
            try
            {
                foreach (SOLine line in PXSelect<SOLine,
                    Where<SOLine.orderType, Equal<Required<SOLine.orderType>>,
                    And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>>>>.Select(orderEntryGraph, parentOrder.OrderType, parentOrder.OrderNbr))
                {
                    if (line.Completed == true)
                    {
                        try
                        {
                            var key = (line.BranchID, line.InventoryID);
                            if (!duplicatedBranchesAndInventories.Contains(key))
                            {
                                SOLine newLine = new SOLine
                                {
                                   // My CODE
                                };
                                orderEntryGraph.Transactions.Cache.Insert(newLine);
                                duplicatedBranchesAndInventories.Add(key);
                            }
                        }
                        catch (Exception ex)
                        {
                            PXProcessing<SOLine>.SetError(new PXException($"Error inserting new line for order {parentOrder.OrderNbr}: {ex.Message}"));
                        }
                    }
                }
                orderEntryGraph.Save.Press();
                ts.Complete();
            }
            catch (Exception ex)
            {
                PXTrace.WriteError(ex);
                throw new PXOperationCompletedException("Error: Issue Generate New Line Items " + ex.Message);
            }
        }
    }
}



I would like it to display like this when pressing Demo Processing


​​​​​​But click the Demo Processing button, it doesn't show the Processing dialog, it shows like this.


I don't know if there is a missing or incorrect piece of code that does it? it not show Processing dialog. So please help me with this problem?
​​​​​​

Hi @PhatPham 

 

I believe you need something like this:

PXProcessing<POFixedDemand>.SetCurrentItem(demand);

if (demand.FixedSource != INReplenishmentSource.Purchased)

                continue;

I think the PXProcessing<> is what gives you the ‘Process’ and ‘Process All’ actions.

Hope this helps.

Aleks


Hi @PhatPham 

 

I believe you need something like this:

PXProcessing<POFixedDemand>.SetCurrentItem(demand); if (demand.FixedSource != INReplenishmentSource.Purchased)                 continue;

I think the PXProcessing<> is what gives you the ‘Process’ and ‘Process All’ actions.

Hope this helps.

Aleks

I already have PXProcessing<>s in my code.

However, the Processing dialog is still not displayed. It just shows such message.

 


Tucked away in the T240 under Implementation of the Processing Action are the following points. I’m in the same position as you with a process that I want to use the screen for. I don’t have the isMassProcess parameter in my method so when I get back to that code, I’ll try that.

In the separate static method, you make the following changes to the code of the graph action:

• You modify the code so that it works with the list of records obtained from the input parameter of the method.

• You add the isMassProcess parameter to the method. If isMassProcess = true is passed in the method parameters (which means that the method is invoked from a processing form), you can return a successful processing message to the UI by using the static PXProcessing<T>.SetInfo() method.

• To handle any errors that might occur during the processing, you enclose the processing code in the try statement. If any error occurs, in the catch statement, you use the static PXProcessing<T>.SetError() method to return the processing result for each record to the UI.

• If the action is used in a workflow, you modify the action definition in the workflow so that the action can be used on the processing form.

In the action definition in the workflow, you call the MassProcessingScreen<>() method with the processing graph as the type parameter. You also call the InBatchMode() method if the workflow action
works with the list of records.


Reply