Reputation: 3783
I need to change the property of a field attribute at runtime. How can I do it?
Upvotes: 4
Views: 458
Reputation: 3783
Way 1
A straightforward way of doing it:
foreach (PXEventSubscriberAttribute attribute in cache.GetAttributes<Field>(dataRecord))
{
PXSomeAttribute someAttribute = attribute as PXSomeAttribute;
if (someAttribute != null)
{
someAttribute.Property = someValue;
}
}
Way 2
A less verbose / arguably more readable way of achieving the same goal with LINQ:
cache
.GetAttributes<Field>(dataRecord)
.OfType<PXSomeAttribute>()
.ForEach(attribute => attribute.Property = someValue);
Source: http://asiablog.acumatica.com/2016/05/dynamically-changing-attribute-property.html.
Upvotes: 3