Solved

Conditionally disabling line level field without writing codes in SOline_Rowselected event


Userlevel 6
Badge +5

Hello,

      We have a need to conditionally disable/enable line level fields. Simply like below:
If SOline.CWI= True, enable “Price per LB”, disable “Unit Price”
While SOline.CWI= false, Disable “Price per LB”, enable “unit price.”

 

 

Actually, this can be achieved before, by putting codes in SOline_rowselected like:
 

        protected void SOLine_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
SOLine soLine = (SOLine)e.Row;
if (soLine != null)
{


SOLineExt soLineExt = PXCache<SOLine>.GetExtension<SOLineExt>(soLine);

if (soLineExt.CWI == true)
{
PXUIFieldAttribute.SetEnabled<SOLine.curyUnitPrice>(cache, soLine, false);
PXUIFieldAttribute.SetEnabled<SOLineExt.usrPricePerLB>(cache, soLine, true);
.....
}
else
{
PXUIFieldAttribute.SetEnabled<SOLine.curyUnitPrice>(cache, soLine, true);
PXUIFieldAttribute.SetEnabled<SOLineExt.usrPricePerLB>(cache, soLine, false);
....

 

However, this would cause performance issue, if user try to input more than 10 lines.

        I tried to put the same codes in SOLine_InventoryID_FieldUpdated, it does not work as expected.

No matter CWI true or NOT, both “price per lb” and “unit price” are enabled after inventory id being input.

icon

Best answer by darylbowman 29 March 2022, 15:45

View original

11 replies

Userlevel 7
Badge +17

Hi, @ray20  Yes, we can do this from the Automation steps from customization packages.

We can add conditions to enable/disable the fields at automation steps in the Customization package. Please find the screenshot for reference.

 

Userlevel 7
Badge +11

Hi @ray20 

We can add the condition like below on the SOLine_Rowselected event or we can use the Automation steps.

            PXUIFieldAttribute.SetEnabled<SOLine.curyUnitPrice>(cache, soLine, soLineExt.CWI == true);
            PXUIFieldAttribute.SetEnabled<SOLineExt.usrPricePerLB>(cache, soLine, soLineExt.CWI == true);

 

 

Badge +11

You can conditionally enable / disable fields with the PXUIEnabled attribute. You can either add the attribute via the CacheAttached event, or for custom fields, right in the field definition. Since you’re working with one of each, I’d suggest you use the CacheAttached event.

 

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
#region Event Handlers

[PXUIEnabled(typeof(Where<SOLineExt.cWI.IsEqual<False>>))]
protected virtual void _(Events.CacheAttached<PX.Objects.SO.SOLine.curyUnitPrice> e)
{ }

[PXUIEnabled(typeof(Where<SOLineExt.cWI.IsEqual<True>>))]
protected virtual void _(Events.CacheAttached<PX.Objects.SO.SOLineExt.usrPricePerLB> e)
{ }

#endregion
}

 

Userlevel 6
Badge +5

Hello @Naveen Boga @darylbowman @jinin 
Thank you all, nice to have your help.
Since I am not good at coding, I will try Naveen’s method first. Still, really appreciated. Thank you.

Userlevel 6
Badge +5

@Naveen Boga @jinin 
Hello, the “conditions” in the automation steps, firstly , it can not be on a line level? 
And secondly, it seems it can not support Customized field?

Userlevel 7
Badge +17

Hi @ray20   Yes, that is correct.

 

If you are going with the custom fields, better go with the code-level customization. Make sure like if you are going with RowSelected event then only Enable/Disable code should be present. 

Or also, you can do with  PXUIEnabled attribute → CacheAttached event.

Userlevel 6
Badge +5

@Naveen Boga 
Thank you buddy. 
1,   Do you know which is having higher/faster performance?
In Rowselected event or in CacheAttached event?
If user is planning to key in more than 30 solines on SO entry screen.

2,  I am not good at coding, so please help
for 
[PXUIEnabled(typeof(Where<SOLineExt.cWI.IsEqual<True>>))]
protected virtual void _(Events.CacheAttached<PX.Objects.SO.SOLine.curyUnitPrice> e) { }
 

it seems to me ,should be


protected virtual void _(Events.CacheAttached<PX.Objects.SO.SOLine.curyUnitPrice> e)

{

[PXUIEnabled(typeof(Where<SOLineExt.cWI.IsEqual<True>>))]

}

Or I shall put another codes in the {} body?

Userlevel 7
Badge +17

@ray20  Both events are the same according to me. 

When any changes happen both events will be triggered and run the code. You can go with any of those approaches.

This code is already above by dary and you can use this.

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
#region Event Handlers

[PXUIEnabled(typeof(Where<SOLineExt.cWI.IsEqual<False>>))]
protected virtual void _(Events.CacheAttached<PX.Objects.SO.SOLine.curyUnitPrice> e)
{ }

[PXUIEnabled(typeof(Where<SOLineExt.cWI.IsEqual<True>>))]
protected virtual void _(Events.CacheAttached<PX.Objects.SO.SOLineExt.usrPricePerLB> e)
{ }

#endregion
}

 

 

Userlevel 6
Badge +5

@Naveen Boga  Yes, I saw the codes. So that’s why I am a poor coder.

Why the event body {} is empty.  Shall we just leave it empty?
 

 

Userlevel 7
Badge +17

@ray20  Yes please, leave it empty.

Userlevel 6
Badge +5

@darylbowman @Naveen Boga 
Hello Coding Pros,
Thank you for your help. Let me update
1, Dary’s code is working. However, since IF both rowselected and cacheattahced events having same performance, I fininally choose to still keep codes in rowselected.
Because it has been tested and run for years without function issues.
And besides making disable or enable, we have still to make a equation that
UnitPrice =  PricebyLB * avgweight,    
so, I decided to do it in rowselected.

2, Upgarding the CPU solved our performance issue.

Still , thank you for your guidance.  Really appreciated to have you guys around.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved