Skip to main content
Answer

PX1070 - is the message misleading?

  • January 27, 2023
  • 1 reply
  • 36 views

Forum|alt.badge.img+7

I have this code that is used to determine if a field on a row is enabled based on the value of another field on the same row.  If the value if the first field changes, that can change the enabled status of the second field.
 

protected void _(Events.FieldSelecting<MyDAC, MyDAC.secondField> e, PXFieldSelecting baseMethod )
{
if (baseMethod != null )
{
baseMethod(e.Cache, e.Args);
}

MyDAC row = e.Row;
if (row != null)
{
if (row.firstField == true)
{
PXUIFieldAttribute.SetEnabled<MyDAC.secondField>(e.Cache, row, false);
}
}
}

However, the PXUIFieldAttribute line of code shows an error PX1070: The state of fields and actions can be configured only in the RowSelected event handler.

This code will compile and it works. So my question is, is the logic used to trigger the PX1070 incorrect?  Or is there a more correct way to achieve this goal? Or do I just ignore PX1070 in this case?

Best answer by Dmitrii Naumov

Acuminator errors are frequently about the best practices and not about code not being able to compile. 

The best practice is to put the logic in RowSelected, because that way you guarantee it to be triggered in 100% of cases when a record is displayed. 

I think the way you have it here may result in incorrectly set enabled status when you change the value of the firstField, but the system does not explicitly reselect the secondField for some reason.

It may be a rare edge case or may not be possible at all, depending on the fields’ positions on the screen.

However, I’d still suggest you to move the logic to RowSelected to be sure it’s 100% correct and for other devs to know where to look for enabling/disabling logic.

1 reply

Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • Answer
  • January 27, 2023

Acuminator errors are frequently about the best practices and not about code not being able to compile. 

The best practice is to put the logic in RowSelected, because that way you guarantee it to be triggered in 100% of cases when a record is displayed. 

I think the way you have it here may result in incorrectly set enabled status when you change the value of the firstField, but the system does not explicitly reselect the secondField for some reason.

It may be a rare edge case or may not be possible at all, depending on the fields’ positions on the screen.

However, I’d still suggest you to move the logic to RowSelected to be sure it’s 100% correct and for other devs to know where to look for enabling/disabling logic.