Linnaire
Linnaire

Reputation: 61

Acumatica - NonStockItem Screen on AlloAddNew in Page

Good Day!

I have a PXSelector field in DAC that only show non-stock items

    public abstract class inventoryID : IBqlField { }

    [PXDBInt]
    [PXSelector(typeof(Search2<InventoryItem.inventoryID,
                                LeftJoin<RECOInventoryItem, On<RECOInventoryItem.inventoryID, Equal<InventoryItem.inventoryID>>>,
                                Where<RECOInventoryItem.inventoryID, IsNull,
                                    And<InventoryItem.itemType, Equal<ItemType.NON_STOCK>,
                                        And<InventoryItem.stkItem, Equal<False>>>>>),
                          typeof(InventoryItem.inventoryCD),
                          typeof(InventoryItem.descr),
                          DescriptionField = typeof(InventoryItem.descr))]
    [PXUIField(DisplayName = "Inventory")]
    [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
    public virtual int? InventoryID { get; set; }

I also have a selector in my page that allows edit and allows add new methods

        <px:PXSelector ID="edInventoryID" runat="server" DataField="InventoryID" AllowEdit="true" AllowAddNew="true">
        </px:PXSelector>

Now, my problem lies with the edit(pencil) button in the User Interface. When I'm clicking the edit button, with the item that i want to edit, I am being redirected to Non-Stock Items page,

But when I want to add another Non-stock Item by using the edit(pencil) button, I am redirected to the Stock Items page.

I already set my PrimaryGraph.

[PXPrimaryGraph(typeof(PropertyMaint))]
public class RECOInventoryItem : Audit, IBqlTable

How do you set the AllowAddNew redirect to Non-Stock Item Page instead of the Stock Item Page.

How do you override the PxPrimaryGraph of the InventoryItem so that the graph that i'm redirecting to is Non-stock Item, instead of Stock Item.

Thank you so much for the advice and suggestions.

Upvotes: 0

Views: 173

Answers (1)

Hugues Beaus&#233;jour
Hugues Beaus&#233;jour

Reputation: 8278

PXPrimaryGraph can handle binding 1 DAC to multiple graphs using BQL conditions on the DAC fields as shown on InventoryItem DAC:

[PXPrimaryGraph(new Type[] 
                {
                   typeof(NonStockItemMaint),
                   typeof(InventoryItemMaint)
                },
                new Type[] 
                {
                   typeof(Where<InventoryItem.stkItem, Equal<False>>),
                   typeof(Where<InventoryItem.stkItem, Equal<True>>)
                })] 

This works well with AllowEdit functionality because the InventoryItem.stkItem field used for the graph redirection is already populated in the record you want to edit.

When you create a new record with AllowAddNew though I suspect the field InventoryItem.stkItem will be null or always defaulted to the same value by PXDefault attribute. This would have the side effect of always redirecting to the same graph.

As you can probably guess AllowAddNew doesn't have any options or programmatic interface to influence it's behavior so it is pretty limited in what it can do. For that reason I don't think you can override it's behavior.

This leave creating your own action button as the only option I know to achieve your use case. You can style the button to show a + icon and no text like AllowAddNew does. You would still be limited on where you can place that button because Selector popup windows also lack options and programmatic interface.

Upvotes: 1

Related Questions