Question

Unable to select multiple Shipments on Process Form

  • 18 April 2021
  • 2 replies
  • 31 views

Good day,

I'm attempting to select multiple shipments on the Create and Print Pick Lists (SO503050) form using the screen-based API, but only the last one in the list is ever selected when performing the Process action.

I'm able to populate the Header Filter section and am getting the shipments (as per the specified filters) back in the Content result.

I'm also able to generate a worksheet using the Process Action, however, it only contains the last shipment that was iterated over and not the 4 shipments that are expected.

Am I missing something? What are the commands needed in order to select more than 1 shipment, so that the worksheet contains more than 1 shipment?

Please see below for additional information & code blocks.

Any and all assistance will be highly appreciated .

--------------------------------------------------------------------------------------------

As can be seen in the screenshot below, the iterative section of the code is able to iterate over all of the shipments that were retrieved from the initial Submit request and seem to add each shipment to the command list:

[...]
// Iterate through all of the results and add our Shipments as necesary 
foreach (SO503050Content result in initialResults)
{
    if (counter <= 4)
    {
        SO503050Shipments shipment = result.Shipments;

        if (shipment.ShipVia.Value == "OFFLINE")
        {
            System.Diagnostics.Debug.WriteLine("Selecting Shipment Nbr: " + shipment.ShipmentNbr.Value);                                        
            commands.Add(new Key { ObjectName = schema.Shipments.ShipmentNbr.ObjectName, FieldName = schema.Shipments.ShipmentNbr.FieldName, Value = "='" + shipment.ShipmentNbr.Value + "'", Commit = true });
            commands.Add(new Value { Value = "True", LinkedCommand = schema.Shipments.Selected, Commit = true });
            counter++;
        }
    }
    else
    {
        break;
    }
}
[...]

 

Each Key in the array represents a unique shipment number:


However, when the Process Action is performed, only 1 shipment has been 'Selected' (from debug logging):


SO503050 - Before:


SO503050 - After:


Created Picking Worksheet:


--------------------------------------------------------------------------------------------
Please see the entire code block below:

using SIHScreenBasedApi.SIH;
using System;
using System.Collections.Generic;
using ProcessStatus = SIHScreenBasedApi.SIH.ProcessStatus;

namespace SIHScreenBasedApi
{
    class Program
    {
        static void Main(string[] args)
        {
            using (Screen context = new Screen())
            {
                try
                {
                    // Login
                    context.CookieContainer = new System.Net.CookieContainer();
                    context.Url = Properties.Settings.Default.SIHScreenBasedApi_SIH_Screen;
                    context.AllowAutoRedirect = true;
                    context.EnableDecompression = true;
                    context.Timeout = 1000000;
                    context.Logout();
                    LoginResult loginResult = context.Login("admin", "Faith1@3");

                    if (loginResult != null && loginResult.Code == ErrorCode.OK)
                    {
                        // Get the schema of the Create Pick List form (SO503050)
                        SO503050Content schema = PX.Soap.Helper.GetSchema<SO503050Content>(context);

                        #region Enter Filter Data
                        // Clear the screen from previous input
                        context.SO503050Clear();

                        // Build list of commands to 'submit' the initial filters, so that we get the shipments we're interested in.
                        List<Command> commands = new List<Command>();

                        commands.Add(new Value { Value = "W", LinkedCommand = schema.Selection.Action });
                        commands.Add(new Value { Value = "WHOLESALE", LinkedCommand = schema.Selection.WarehouseID, Commit = true });
                        commands.Add(new Value { Value = "1", LinkedCommand = schema.SelectionProcessParameters.MaxNumberOfPickers });
                        commands.Add(new Value { Value = "4", LinkedCommand = schema.SelectionProcessParameters.MaxNumberOfTotesPerPicker });
                        commands.Add(schema.Shipments.Selected);
                        commands.Add(schema.Shipments.ShipmentNbr);
                        commands.Add(schema.Shipments.ShipVia);

                        SO503050Content[] initialResults = context.SO503050Submit(commands.ToArray());
                        int counter = 0;
                        #endregion
                        
                        if (initialResults.Length > 0)
                        {
                            #region Iterate Results and Select Shipments
                            // Remove some commands, as we don't need them anymore.
                            commands.Remove(schema.Shipments.Selected);
                            commands.Remove(schema.Shipments.ShipmentNbr);
                            commands.Remove(schema.Shipments.ShipVia);

                            // Iterate through all of the results and add our Shipments as necesary 
                            foreach (SO503050Content result in initialResults)
                            {
                                if (counter <= 4)
                                {
                                    SO503050Shipments shipment = result.Shipments;

                                    if (shipment.ShipVia.Value == "OFFLINE")
                                    {
                                        System.Diagnostics.Debug.WriteLine("Selecting Shipment Nbr: " + shipment.ShipmentNbr.Value);                                        
                                        commands.Add(new Key { ObjectName = schema.Shipments.ShipmentNbr.ObjectName, FieldName = schema.Shipments.ShipmentNbr.FieldName, Value = "='" + shipment.ShipmentNbr.Value + "'", Commit = true });
                                        commands.Add(new Value { Value = "True", LinkedCommand = schema.Shipments.Selected, Commit = true });
                                        counter++;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            #endregion

                            if (counter > 0)
                            {
                                #region Submit Selected Shipments
                                // Add the final command, which is to process the selected items
                                commands.Add(schema.Actions.Process);
                                
                                // Submit the commands
                                context.SO503050Submit(commands.ToArray());

                                // Get process result
                                ProcessResult longProcess = context.SO503050GetProcessStatus();

                                while (longProcess.Status == ProcessStatus.InProcess)
                                {
                                    System.Diagnostics.Debug.WriteLine("In Long Running Process");
                                    System.Threading.Thread.Sleep(1000);
                                    longProcess = context.SO503050GetProcessStatus();
                                }

                                if (longProcess.Status == ProcessStatus.Completed)
                                {
                                    // Fetch the processed result picksheet number                                    
                                    commands.Clear();
                                    commands.Add(schema.Shipments.ShipmentNbr);
                                    commands.Add(schema.Shipments.WorksheetNbr);

                                    SO503050Content[] finalResults = context.SO503050Submit(commands.ToArray());

                                    foreach (SO503050Content result in finalResults)
                                    {
                                        SO503050Shipments processedShipment = result.Shipments;
                                        System.Diagnostics.Debug.WriteLine("Shipment Nbr: " + processedShipment.ShipmentNbr.Value + ", Worksheet Nbr: " + processedShipment.WorksheetNbr.Value);
                                    }
                                }
                                
                                if (longProcess.Status == ProcessStatus.NotExists)
                                {
                                    System.Diagnostics.Debug.WriteLine("Process Didn't Exist");
                                }

                                if (longProcess.Status == ProcessStatus.Aborted)
                                {
                                    System.Diagnostics.Debug.WriteLine("Process was Aborted");
                                }
                                #endregion

                                var finalbreakpoint = "b";
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    var blah = "e";
                }
                finally
                {
                    context.Logout();
                }
            }
        }
    }
}

 

 

Once again, any and all assistance will be highly appreciated (I've been hitting my head on this one for quite some time - but I'm hopeful that it's just a matter of changing commands around in order to get the desired result)


2 replies

Userlevel 1
Badge

Maybe you can write a loop to confirm that the Selected field value is True after you’ve set it?  The issue might be that the Selected value isn’t persisting the way that you need and so only the last shipment is Selected before you invoke the submit action.

Also, I see this line of code:

commands.Add(schema.Actions.Process);

Just a shot in the dark but are you sure you don’t want something like:

commands.Add(schema.Actions.ProcessAll);

Hi @ddunn ,

Thank you for the input & suggestions. I will give the loop another shot, when I tried it before, I would get the shipments back with their selected value set to False again.

 

Just a shot in the dark but are you sure you don’t want something like:

commands.Add(schema.Actions.ProcessAll);

 

I believe this action is linked to the literal Process All action, which would then include all of the shipments into the worksheet, instead of the 4 ‘selected’ ones.

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 — 2020  Acumatica, Inc. All rights reserved