Solved

How do I get a recordset of InventoryItems I can iterate through within an Action?

  • 6 September 2022
  • 3 replies
  • 179 views

Userlevel 5
Badge +1

I am trying to create a customization to iterate through inventory items to update Prices in a BigCommerce store from a custom field I created called usrAIWHLPrice on an InventoryItem extension.

 

I have created a new screen with a datasource which is based on a query that checks for that field not being null:

public SelectFrom<InventoryItem>
.Where<InventoryItemExt.usrAIWHLPrice.IsNotNull>
.View InvItems;

I am still getting to grips with how to do things in Acumatica so decided to just create a simple action as a first step that will create a list of inventoryitems I can iterate through and pull out the information I need. 

I created a button with an action:

 

public PXAction<InventoryItem> prepareWHLData;
[PXButton]
[PXUIField(DisplayName = "Prepare WHL Data",
MapEnableRights = PXCacheRights.Select,
MapViewRights = PXCacheRights.Select)]
protected void PrepareWHLData()
{
PXTrace.WriteInformation("Preparing data...");

var invItems = SelectFrom<InventoryItem>
.Where<InventoryItemExt.usrAIWHLPrice.IsNotNull>
.View.Select(this);


if (invItems == null) {
PXTrace.WriteInformation("null items");
}
else
{
foreach (var item in invItems)
{
PXTrace.WriteInformation("items found:");
}
}
}

This validates and runs but when I click the button and step through it in Visual Studio the query throws an exception saying it’s a single record requested and only returns a single record instead of the three I’m expecting.

I’m presuming this is because of using View.Select(this) but I don’t know what else to put there that will get me a recordset containing the three expected records.

 

Can anyone give me a pointer?

 

Thanks for any help/advice,

 

Phil

 

icon

Best answer by ppowell 7 September 2022, 02:51

View original

3 replies

Userlevel 5
Badge +2

@ppowell Is the issue that the Trace is printing “items found” only once?

I replicated your logic and got the same outcome.

Try to change the foreach from using var to explicitly indicating the class InventoryItem.

Here is a sample of code adapted to my environment

            PXTrace.WriteInformation("Preparing data...");

var invItems = SelectFrom<InventoryItem>
.Where<InventoryItem.inventoryCD.IsNotNull>
.View.SelectWindowed(this.Base, 0, 10);


if (invItems == null)
{
PXTrace.WriteInformation("null items");
}
else
{
foreach (InventoryItem item in invItems)
{
PXTrace.WriteInformation("items found:" + item.InventoryCD);
}
}

And here is the result

 

Userlevel 5
Badge +1

@Fernando Amadoz and @rajeshvemunoori31  Thanks, that is what I needed. Confirmation that it should work really helped as it made me think about why it didn’t work some more.  I had to cast the item to InventoryItem and used the view I had already created as the datasource rather than creating a new one.  I have it working now with the following:

 

using System;
using PX.Data;
using PX.Data.BQL.Fluent;
using PX.Objects;
using PX.Objects.IN;

namespace PPTransferWholeSalePriceListsToBC
{

public class ACPriceListToBC : PXGraph<ACPriceListToBC, InventoryItem>
{

// region Buttons

// Define action for Prepare WHL Data

public PXAction<InventoryItem> prepareWHLData;
[PXButton]
[PXUIField(DisplayName = "Prepare WHL Data",
MapEnableRights = PXCacheRights.Select,
MapViewRights = PXCacheRights.Select)]
protected void PrepareWHLData()
{
PXTrace.WriteInformation("Preparing data...");

if (InvItems == null) {
PXTrace.WriteInformation("null items");
}
else
{
foreach (InventoryItem item in InvItems.Select())
{
InventoryItemExt itemExt = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(item);

PXTrace.WriteInformation("items found: " + item.InventoryCD + " - " + itemExt.UsrAIWHLPrice);

// Export WHL Price here
}
}
}

// end region

// Datasource for the screen

public SelectFrom<InventoryItem>
.Where<InventoryItemExt.usrAIWHLPrice.IsNotNull>
.View InvItems;

}
}

Thanks for all your help,

 

Phil

Userlevel 1
Badge

Hello @ppowell ,

 

Your code looks perfect and I just added the same code in one of the existing graph and it worked fine for me without any issue.

 

I’m not sure but can you try by creating a view for your query and then access it in your button for items iteration. 

public SelectFrom<InventoryItem>
.Where<InventoryItem.basePrice.IsNotNull>
.View invitems;


public PXAction<FSServiceOrder> prepareWHLData;
[PXButton]
[PXUIField(DisplayName = "Prepare WHL Data",
MapEnableRights = PXCacheRights.Select,
MapViewRights = PXCacheRights.Select)]
protected void PrepareWHLData()
{
//var invItems = SelectFrom<InventoryItem>
// .Where<InventoryItem.basePrice.IsNotNull>
// .View.Select(Base);
if (invitems.Select().Count == 0)
PXTrace.WriteInformation("null items");
else
{
foreach (var item in invitems.Select())
PXTrace.WriteInformation("items found:");
}
}

 

Thanks

 

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