Home Blog Extending Attribute Searches in Acumatica

Extending Attribute Searches in Acumatica

Sharif Ahammad | December 3, 2018

The purpose of this post is to show developers how easy it is to extend the search functionality of Acumatica where a discrete limitation may lie through a simple coding example.  In this particular case, the limitation in searching SKU’s which have unique identifiers.  We can easily overcome this limitation by adding a simple attribute search feature.

Extending Attribute Searches in Acumatica

We were approached by a company who has one of a number of business processes that require that their SKU’s be searched using attributes. They have a set of unique identifiers for each SKU and wanted the SKUs to be searchable when scanned. This has been a limitation on the current inventory search and presented us with a challenge to come up with a solution without disrupting the current functionality of  the system.

Fortunately, Acumatica provides the required flexibility for us to create custom attribute fields on different entities such as Customers, Vendors, and Stock Items, etc. Each Stock Item for example, can consist of a list of attributes that can be set on the attributes tab. However, this cannot be used to search SKUs, unfortunately.

The Solution: Custom Attributes

To overcome this limitation, we came up with a solution by making use of custom attributes¹ and taking an array of attributes as arguments that fetches the values of the attributes from the CSAnswers table for each SKU. Also, we utilized a DAC Extension² and edited a few properties to achieve the functionality the customer required.  More on this below.

There are three steps necessary to accomplish this task.

Firstly, we implement a custom attribute which has a constructor taking three arguments:

  1. An array of strings to specify the attribute names
  2. ClassID
  3. NoteID

Since Attributes are assigned to the Item class, ClassID is passed as an argument to a constructor along with the NoteID, which has a unique value for each SKU in the CSAnswers table.

The AttributeFieldselecting method in the constructor takes the names of attributes as a parameters and checks the CSAnswers table. If the attribute name exists for a particular item, it fetches its associated value. Below is the sample code for the custom attribute.


public class PXAddAtttributeColumns : CRAttributesFieldAttribute
{
string[] _names;
public PXAddAtttributeColumns(string[] names, Type classID, Type noteID)
: base(classID, noteID)
{
_names = names;
}

public override void CacheAttached(PXCache sender)
{
this._IsActive = true;
base.CacheAttached(sender);
}

protected override void AttributeFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, PXFieldState state, string attributeName, int idx)
{
if (_names.Any(attributeName.Equals))
{

state.DisplayName = (!String.IsNullOrEmpty(state.DisplayName)) ? (state.DisplayName.Replace(“$Attributes$-“, “”)) : attributeName;
state.Visible = true;
state.Visibility = PXUIVisibility.Dynamic;
}
base.AttributeFieldSelecting(sender, e, state, attributeName, idx);
}
}

Second, we extend the InventoryItem DAC to add attributes columns. These columns have attribute values for each SKU – if it exists.  Below you will see a code snippet showing a way to achieve this, along with a sample screenshot in the UI.

Here is an example of  the custom attribute we utilized:


public class InventoryItemExt : PXCacheExtension

{
public abstract class itemAttributes : IBqlField { }
[PXAddAtttributeColumns(new[] { “ASIN” },
typeof(InventoryItem.itemClassID),
typeof(InventoryItem.noteID))]
public virtual string[] ItemAttributes { get; set; }
}

Lastly, an attribute name is set to the FastFilterFields property on Aspx  page and a screenshot showing the SKUs filtered are as shown below.


<px:PXSegmentMask CommitChanges="True" ID="edInventoryID" runat="server" DataField="InventoryID" AllowEdit="True" AutoRefresh="True">
<Parameters>
<px:PXControlParam ControlID="grid" Name="POLine.lineType" PropertyName="DataValues[&quot;LineType&quot;]" Type="String" >
</px:PXControlParam>
</Parameters>
<GridProperties FastFilterFields="ASIN_ItemAttributes" />
</px:PXSegmentMask>

Conclusion

In summary, by using Acumatica’s custom attributes and DAC extensions, you can easily build an attribute search feature, overcoming a limitation in searching SKUs with unique identfiers.  Customers can make use of this functionality to simply key in the appropriate attribute value and fetch the SKUs they were looking to examine. This benefits customers who have unique identifiers for  their SKUs. One such example would include the Amazon Standard Identification Number (ASIN) that can be used as an attribute for each item in inventory.


¹To learn more about custom attributes, refer to both the Custom Developer Guide and the Framework Developer Guide

²Ibid

Related Posts

Blog Author

Delivery Head at Kensium Solutions

Receive blog updates in your Inbox.