Reputation: 479
Good day
I have created a custom attribute for the customer ID attribute on Sales orders. With the current attributes on the Customer ID customers that are in credit hold are not shown in the list.
My idea is to change the list dynamically so that if the order type is QT customers that are in credit hold still show in the list.
My problem is I don't know if there is a way to send/get the current SOOrder.OrderType
Here is where I am at
namespace PX.Objects.SO
{
[PXNonInstantiatedExtension]
public class SO_SOOrder_ExistingColumn : PXCacheExtension<PX.Objects.SO.SOOrder>
{
#region CustomerID
[PXMergeAttributes(Method = MergeMethod.Append)]
// [CustomercustomersAttribute(Current<SOOrder.orderType>))]
[CustomercustomersAttribute()]
public int? CustomerID { get; set; }
#endregion
}
public class CustomercustomersAttribute : PXCustomSelectorAttribute
{
public string orderType { get; set; }
public Type orderType2 { get; set; }
public CustomercustomersAttribute(Type OrderType) : base(typeof(Customer.acctCD))
{
this.orderType2 = OrderType;
this.DescriptionField = typeof(Customer.acctName);
}
public CustomercustomersAttribute(string OrderType) : base(typeof(Customer.acctCD))
{
this.orderType = OrderType;
this.DescriptionField = typeof(Customer.acctName);
}
public CustomercustomersAttribute() : base(typeof(Customer.acctCD))
{
this.DescriptionField = typeof(Customer.acctName);
}
protected virtual IEnumerable GetRecords()
{
foreach (Customer pc in PXSelect<Customer>.Select(this._Graph))
{
if (pc.Status != "A")
{
// Here I want to do the check if
if (orderType.ToString() == "QT")
{
yield return pc;
}
}
else
{
yield return pc;
}
}
}
}
}
Upvotes: 0
Views: 363
Reputation: 498
It's always a good idea to use existing attributes when possible.
In you case it looks like you could get the desired behavior using PXRestrictorAttribute
. It adds a restriction to a BQL command that selects data for a lookup control and displays the error message when the value entered does not fit the restriction.
Here is a nice article from Sergey Marenich from Acumatica about PXRestrictor.
This is how you could write your restrictor. Note we use the ReplaceInherited
property to override the existing restrictor for active customers:
using System;
using PX.Data;
using PX.Objects.Common;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.SO;
namespace PX.Objects.SO
{
#region CustomerID
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRestrictor(typeof(Where<Customer.status, IsNull,
Or<Customer.status, Equal<BAccount.status.active>,
Or<Customer.status, Equal<BAccount.status.oneTime>,
Or2<Where<Customer.status, Equal<BAccount.status.Hold>, And<Current<SOOrder.orderType>,Equal<SOOrderTypeConstants.quoteOrder>>>>
>>>), "Customer status is {0} and this is not a quote", typeof(Customer.status), ReplaceInherited = true)]
public virtual int? CustomerID { get; set; }
#endregion
}
Bonus: If this is the only customization you need, you can add this directly in a customization project from the UI without needing an actually compile an extension library.
Upvotes: 0
Reputation: 8268
Try obtaining the current cache object from Graph Caches
collection:
Type fieldType = [...];
var cache = _Graph.Caches[BqlCommand.GetItemType(fieldType)];
var currentCacheObject = cache.Current;
Upvotes: 1