Kyle Vanderstoep
Kyle Vanderstoep

Reputation: 771

Adding a Detail Grid to Sales Category (IN204060) - Parent/Child Issue

I am trying to add a detail grid tied to the selected sales category on the Sales Category screen (IN204060)

Created a DAC that holds the grid data:

public class INCategoryFilesCTC : IBqlTable
{
#region CategoryID
[PXDBInt(IsKey = true)]
[PXUIField(DisplayName = "Category ID")]
public virtual int? CategoryID { get; set; }
public abstract class categoryID : IBqlField { }
#endregion

#region Type
[PXDBString(1, IsFixed = true, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Type")]
public virtual string Type { get; set; }
public abstract class type : IBqlField { }
#endregion

#region NoteID
[PXNote()]
[PXUIField(DisplayName = "Price Source")]
public virtual Guid? NoteID { get; set; }
public abstract class noteID : IBqlField { }
#endregion

#region Uploaded
[PXDBDate()]
[PXUIField(DisplayName = "Uploaded")]
public virtual DateTime? Uploaded { get; set; }
public abstract class uploaded : IBqlField { }
#endregion

#region FileName
[PXDBString(50, IsFixed = true, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "File Name")]
public virtual string FileName { get; set; }
public abstract class fileName : IBqlField { }
#endregion
}

Then added a data view delegate select (was having issues with Current<> due to the non standard selects for the rest of the graph data)

        public PXSelect<INCategoryFilesCTC> CategoryFiles;
    protected virtual IEnumerable categoryFiles()
    {
        var cache = Base.Caches[typeof(INCategoryFilesCTC)];
        cache.AllowInsert = true;
        cache.AllowUpdate = true;
        cache.AllowDelete = true;

        var select = PXSelect<INCategoryFilesCTC, 
            Where<INCategoryFilesCTC.categoryID, 
            Equal<Required<INCategoryFilesCTC.categoryID>>>>.Select(Base,Base.Folders.Current.CategoryID).FirstTableItems;
        foreach (INCategoryFilesCTC item in select)
        {
            cache.SetStatus(item,PXEntryStatus.Held);
        }

        return cache.Cached;

    }

The grid lives inside of 1/2 of a split container, and inside a tab. Search for ID="WebFiles" ( is the half it lives in, figured I wouldn't drown you guys with aspx code, if you want the rest let me know)

        <Template2>
        <px:PXFormView ID="form" runat="server" DataSourceID="ds" DataMember="CurrentCategory" 
            Caption="Category Info" Width="100%">
            <Template>
                <px:PXLayoutRule ID="PXLayoutRule1" runat="server" StartColumn="True" LabelsWidth="S" ControlSize="SM" />
                <px:PXTextEdit ID="edDescription" runat="server" DataField="Description" CommitChanges="True" />
                <px:PXLayoutRule ID="PXLayoutRule2" runat="server" StartColumn="True" LabelsWidth="S" ControlSize="SM" />
                <px:PXTreeSelector ID="edParentID" runat="server" DataField="ParentID" ShowRootNode="False"
                    TreeDataMember="ParentFolders" TreeDataSourceID="ds" AutoRefresh="True" ExpandDepth="1"
                    SyncPosition="True" DataMember="ParentFolders" AutoRepaint="True" CommitChanges="True" KeepPosition="True">
                    <DataBindings>
                        <px:PXTreeItemBinding DataMember="ParentFolders" TextField="Description" ValueField="CategoryID" />
                    </DataBindings>
                </px:PXTreeSelector>
                <px:PXLayoutRule ID="PXLayoutRule3" runat="server" StartColumn="True" LabelsWidth="S" ControlSize="SM" />
            </Template>
        </px:PXFormView>
        <px:PXTab runat="server" >
            <Items>
            <px:PXTabItem Text="Category Members">
                <Template>
                    <px:PXGrid ID="gridMembers" runat="server" ActionsPosition="Top" Width="100%"
                    SkinID="Details" CaptionVisible="true" SyncPosition="True" 
                    AutoRepaint="True" AdjustPageSize="Auto">
                    <AutoSize Enabled="True" Container="Parent"/>
                    <Mode InitNewRow="True"></Mode>
                    <Levels>
                        <px:PXGridLevel DataMember="Members">
                            <Columns>
                                <px:PXGridColumn AllowCheckAll="True" AllowNull="False" DataField="CategorySelected" TextAlign="Center"
                                    Type="CheckBox" Width="26px" />
                                <px:PXGridColumn DataField="InventoryID" CommitChanges="true" Width="140px" LinkCommand="viewDetails"/>
                                <px:PXGridColumn DataField="InventoryItem__Descr" Width="200px"/>
                                <px:PXGridColumn DataField="InventoryItem__ItemClassID" Width="140px"/>
                                <px:PXGridColumn AllowNull="False" DataField="InventoryItem__ItemStatus" RenderEditorText="True" Width="100px"/>
                            </Columns>
                        </px:PXGridLevel>
                    </Levels>
                    <ActionBar>
                        <Actions>
                            <Search Enabled="False" />
                            <EditRecord Enabled="False" />
                            <NoteShow Enabled="False" />
                            <FilterShow Enabled="False" />
                            <FilterSet Enabled="False" />
                            <ExportExcel Enabled="False" />
                        </Actions>
                        <CustomItems>
                            <px:PXToolBarButton Tooltip="Copy Selected Inventory Items" DisplayStyle="Image">
                                <AutoCallBack Command="Copy" Enabled="True" Target="ds" />
                                <Images Normal="main@Copy" />
                            </px:PXToolBarButton>
                            <px:PXToolBarButton Tooltip="Cut Selected Inventory Items" DisplayStyle="Image">
                                <AutoCallBack Command="Cut" Enabled="True" Target="ds" />
                                <Images Normal="main@Cut" />
                            </px:PXToolBarButton>
                            <px:PXToolBarButton Tooltip="Paste Inventory Items from Buffer" DisplayStyle="Image">
                                <AutoCallBack Command="Paste" Enabled="True" Target="ds" />
                                <Images Normal="main@Paste" />
                            </px:PXToolBarButton>
                            <px:PXToolBarButton>
                                <AutoCallBack Command="AddItemsbyClass" Target="ds" />
                            </px:PXToolBarButton>
                            <px:PXToolBarButton Text="Inventory Details" Key="cmdviewDetails" Visible="False">
                                <AutoCallBack Command="viewDetails" Target="ds" />
                            </px:PXToolBarButton>
                        </CustomItems>
                    </ActionBar>
                </px:PXGrid>
                </Template>
            </px:PXTabItem>
            <px:PXTabItem Text="Website Media">
                <template>
                    <px:PXFormView ID="WebForm" runat="server" DataSourceID="ds" DataMember="CurrentCategory">
                        <Template>
                            <px:PxTextEdit ID="txtVideoURL" runat="server" DataField="CTCVideoURL" />
                            <px:PxTextEdit ID="txtCategoryDesc" runat="server" DataField="CTCCategoryDesc" />
                        </Template>
                    </px:PXFormView>
                    <px:PXGrid ID="WebFiles" runat="server" FilesIndicator="True" Height="300px" Width="100%"  DataSourceID="ds">
                        <Levels>
                            <px:PXGridLevel DataMember="CategoryFiles" DataKeyNames="CategoryID">
                                <Columns>
                                    <px:PXGridColumn DataField="CategoryID" />
                                    <px:PXGridColumn DataField="Type" />
                                    <px:PXGridColumn DataField="Filename" />
                                    <px:PXGridColumn DataField="Uploaded"/>
                                </Columns>
                            </px:PXGridLevel>
                        </Levels>
                        <ActionBar>
                            <Actions>
                                <Delete Enabled="True" />
                                <AddNew Enabled="True" />
                            </Actions></ActionBar>
                    </px:PXGrid>
                </template>
            </px:PXTabItem>
            </Items>
        </px:PXTab>         
    </Template2>

When I select a tree element, if there are records that would show up in my custom table (tree element categoryID = grid record categoryID) I get the following error:

Error: an invalid argument has been specified
Parameter name selectParent

Absolutely nothing comes up in trace, and nothing comes up during debugging, so I am at a bit of a loss.

A few things:

This lends me to believe something is happening on the select of the detail records. Any advice?

Thanks -Kyle

Upvotes: 0

Views: 246

Answers (1)

Kyle Vanderstoep
Kyle Vanderstoep

Reputation: 771

OK, this turned out to be more basic than I thought.. whoops. If you want to skip reading it turned out to be due to a simple key issue on the detail records

First off, I removed the data view delegate, the "Current" Sales category ID was coming through fine

   public PXSelect<INCategoryFilesCTC,
      Where<INCategoryFilesCTC.categoryID,
      Equal<Current<INCategory.categoryID>>>> CategoryFiles;

Second off, added the correct PXParent and PXDBdefault attributes for the master-detail link (on field CategoryID)

#region CategoryID
[PXDBInt(IsKey=true)]
[PXParent(typeof(Select<INCategory, Where<INCategory.categoryID,  Equal<Current<INCategory.categoryID>>>>))]
[PXDBDefault(typeof(INCategory.categoryID))]
public virtual int? CategoryID { get; set; }
public abstract class categoryID : IBqlField { }
#endregion

But lastly I added a Row# style column that used attribute [PXLineNbr]

#region CatFileKey
[PXDBInt(IsKey=true)]
[PXLineNbr(typeof(INCTC001INCategory.ctcPrevFileNumber))]
public virtual int? CatFileKey { get; set; }
public abstract class carFileKey : IBqlField { }
#endregion

And having this second key fixed my problem immediately

So all in all an error that I thought was due to some difficult customization was really because of some extremely basic thing ha ha.. hopefully this post prevents people from forgetting the same thing

Upvotes: 0

Related Questions