One More Example Of Selectors
07 May 2017
Hello everybody,
today I want to present one more example of selectors, but the one, that has multiple fields in it.
Consider following code:
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using PX.Data; using PX.Objects.CS; using PX.Objects.CT; using PX.Objects.DR; namespace MyBlog { public class DeliverySelectorAttribute : PXCustomSelectorAttribute { public DeliverySelectorAttribute(Type selectorField, params System.Type[] fieldList) : base(selectorField, fieldList) { } public override void FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { } string[] validIds = new[] { "FEDEX 1 CLS", "OLX PR EX", "AMAZON PRIOR" }; protected virtual IEnumerable GetRecords() { var selectedValues = PXSelect<Carrier>.Select(this._Graph); var result = new List<Carrier>(); foreach (PXResult<Carrier> selectedValue in selectedValues) { if (validIds.Contains(selectedValue.GetItem<Carrier>().CarrierID)) { result.Add(selectedValue); } } return result; } } }
If to compare it with previous selector code it have option of choice of multiple columns instead of showing only one columng.
Later in your program you can reuse this selector like this:
Snippet
[DeliverySelector(typeof(Carrier.carrierID), new System.Type[] { typeof(Carrier.carrierID), typeof(Carrier.description),
typeof(Carrier.isCommonCarrier), typeof(Carrier.confirmationRequired), typeof(Carrier.packageRequired) },
CacheGlobal = true, DescriptionField = typeof(Carrier.description))]
New selector format allows you to display any kind of special selector fields.