Brian Stevens
Brian Stevens

Reputation: 1951

What are the minimum requirements to add PXSearchable related to a new table in a graph extension?

Acumatica ERP 2018R1 - Build 18.107.0022

The goal was simple. Add a new tab to the Acumatica ERP Stock Items screen to show a 1 to many relationship of custom data related to the item.

After some help here with how to get the new PXSearchable data into the Rebuild Full-Text Index screen, the SearchIndex table populates with my data, showing both the title line data and the searchable fields in the content field. However, the search results displayed are simply a colon... the colon that is supposed to separate my 2 data elements displayed in the title line since the format of the title is "{0} : {1}".

The data is in the content field of the database table, but does not display on the search results. Only a blank line with my : appears, which does take me to the Stock Items screen for my item found via the search.

Graph Extension:

  public class InventoryItemMaint_Extension : PXGraphExtension<InventoryItemMaint>
  {
        #region Customized Data Views
        public PXSelect<MyDataTable, Where<MyDataTable.inventoryID, Equal<Current<InventoryItem.inventoryID>>>> myviewname;
        #endregion

  }

DAC Definition

    [Serializable]

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

    [PXCacheName("My Data Description")]

    [PXBreakInheritance]

    public class MyDataTable: IBqlTable
    {
        #region BranchID
        [PXDBInt(IsKey = true)]
        [PXDefault(typeof(Current<AccessInfo.branchID>))]
        public virtual Int32? BranchID { get; set; }
        public abstract class branchID : PX.Data.IBqlField { }
        #endregion

        #region InventoryID
        [PXDBInt]
        [PXDBDefault(typeof(InventoryItem.inventoryID))]
        [PXParent(typeof(Select<InventoryItem, Where<InventoryItem.inventoryID, Equal<Current<MyDataTable.inventoryID>>>>))]
        public virtual int? InventoryID { get; set; }
        public abstract class inventoryID : IBqlField { }
        #endregion

#region MyFieldsHere
#endregion

        #region NoteID  
        public abstract class noteID : PX.Data.IBqlField
        {
        }
        protected Guid? _NoteID;
        [PXSearchable(PX.Objects.SM.SearchCategory.All, "{0}: {1}",
            new Type[] { typeof(MyDataTable.MasterDataID), typeof(MyDataTable.MySearchableDataField) },
            new Type[] { typeof(MyDataTable.MySearchableDataField) },
            NumberFields = new Type[] { typeof(MyDataTable.MySearchableDataField) },
            Line1Format = "{0} - {1}", Line1Fields = new Type[] { typeof(MyDataTable.MasterDataID), typeof(MyDataTable.MySearchableDataField) },
            Line2Format = "{0}", Line2Fields = new Type[] { typeof(MyDataTable.MySearchableDataField) },
            WhereConstraint = typeof(Where<Current<MyDataTable.active>, NotEqual<False>>)
            )]
        [PXNote]
        public virtual Guid? NoteID { get; set; }
        #endregion

I have used DAC's for InventoryItem and POOrder as examples to follow as well as various search results on the internet. I could not find anything telling me to define PXCacheName to make it display a value in the "Name" column on the Rebuild Full-Text Index screen, so it seems in similar fashion that I must be missing something else that everyone else takes for granted.

What is necessary to get the search results to display properly on the search results screen?

Upvotes: 1

Views: 331

Answers (2)

Brian Stevens
Brian Stevens

Reputation: 1951

The missing link appears to be that the Searchable object needs to have it's own graph/screen for the presentation layer to connect. I had added my custom data as a new tab hanging off the Inventory Item. When the Rebuild Full-Text Index ran, it was pointing to the graph for the Stock Item screen and ultimately the InventoryItem record.

By creating a dedicated graph/screen for the presentation of my custom data, PXSearchable was able to link to the custom data's graph (noted via [PrimaryGraph(typeof(MyGraph))].

The index was rebuilding with the expected data because the index rebuild does not appear to rely on the presentation layer's graph definitions. However, the display of real-time search results does go through the presentation layer to provide a viewable screen result and subsequent link to the primary graph.

To do this again in the future, these appear to be the required code elements:

---DAC---

[PXPrimaryGraph(typeof(MyCustomDataDedicatedGraph))]
[PXCacheName("User Friendly Cache Name Displayed In Rebuild Index Screen")]

#region NoteID  
[PXSearchable(PX.Objects.SM.SearchCategory.IN, "{0}",
new Type[] { typeof(MyDataTable.myTitleField1) },
new Type[] { typeof(MyDataTable.myIndexedField1) },
NumberFields = new Type[] { typeof(MyDataTable.myIndexField1) },
Line1Format = "{0}", Line1Fields = new Type[] { typeof(MyDataTable.myDescriptionLine1Field1) },
Line2Format = "{0}", Line2Fields = new Type[] { typeof(MyDataTable.myDescriptionLine2Field1) },
WhereConstraint = typeof(Where<Current<MyDataTable.myActiveFlagField>, NotEqual<False>>)
)]
[PXNote]
public virtual Guid? NoteID { get; set; }
public abstract class noteID : IBqlField { }
#endregion

---Graph MyCustomDataDedicatedGraph---

PXSelect or PXSelectJoin the data view needed to fully
represent the data in the PXSearchable of the NoteID of the DAC

Note: If joining tables, remember to use the MatchWithJoin and SelectForFastIndexing parameters in the PXSearchable section. Good examples are in the CodeRepository folder for IN/DLC/InventoryItem.cs and PO/DLC/POOrder.cs.

Upvotes: 1

Brendan
Brendan

Reputation: 5623

This was to long for a comment so these are just more questions/things to try...

If you are looking to give your dac a cache name you use the PXCacheName attribute on the DAC like so...

[Serializable]
[PXCacheName("My Cache Name")] 
public class MyDataTable: IBqlTable
{
    //...
}

the first set of values from your example new Type[] { typeof(MyDataTable.MasterDataID), typeof(MyDataTable.MySearchableDataField) } would be the values that display in the " : " value. I assume they have values in the table and would assume they are pointing to the abstract class of the field name using the lowercase field name of MyDataTable.masterDataID for example.

I have setup custom DACs to be searchable and it did take some trial and error to see what shows up and what makes sense.

Not sure if it matters but are those fields (MasterDataID & MySearchableDataField) string fields? Try different fields (string fields) to confirm? I did use a date field and works but not for the search field you are seeing as blank.

I would assume changes to the searchable attribute also require to rebuild the indexes. I would start with trying different string fields just to confirm that first.

Shouldn't make a difference but I used PX.Objects.SM.SearchCategory.IN in place of all.

Upvotes: 0

Related Questions