Gabriel
Gabriel

Reputation: 3783

How can you dynamically change the property of a field attribute for a given data record?

I need to change the property of a field attribute at runtime. How can I do it?

Upvotes: 4

Views: 458

Answers (1)

Gabriel
Gabriel

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

Related Questions