Solved

Field Validation not Called After SetValueExt

  • 20 November 2022
  • 6 replies
  • 207 views

Userlevel 3
Badge +1

Trying to set the customer based on the selection of a project. However I get a validation error.

 

 

    public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{
protected void (Events.FieldUpdated<SOOrder, SOOrder.projectID> e)
{
if (e.Row == null) return;
SOOrder so = (SOOrder)e.Row;

if(so.CustomerID == null && so.ProjectID != null)
{
var prj = PMProject.PK.Find(e.Cache.Graph,so.ProjectID);

e.Cache.SetValue<SOOrder.customerID>(e.Row, prj.CustomerID ?? null);
}
}
}

results in when the project is selected.

 

I have tried both SetValueExt and SetValue, SetValueExt causes the ProjectId to be set to null or “X”, while SetValue works as intended with the exception of the validation error.

The validation error occurs in both cases.

Unselecting the project, and then reselecting the project causes the error to go away. 

 

How can I request the project field be revalidated for validation? or can I just clear the error?

 

I could not find the source of this validation error in SOOrderEntry, any ideal on how to locate the source?

 

Thanks

 

 

 

 

 

icon

Best answer by Leif 30 November 2022, 06:04

View original

6 replies

Userlevel 4
Badge +1

Hi @Leif,

Add the below line in your selector:

 ValidateValue = false.

Ex: 

[PXSelector(typeof(PMTask.taskID),
            SubstituteKey = typeof(PMTask.taskCD),
            ValidateValue = false)]

 

Note: in PXSelector the default ValidateValue = true which is implicit.

 

Hope this may help you!

Thanks,

Moulali Shaik.

Userlevel 3
Badge +1

Two things, the validation error is not related to the Task, but to the Project. Also I would like validation to continue, as the logic is correct, just the order of operations is not. In otherwards the validation event for Customer is executing prior to the Project being update, so I just need to revalidate.

 

Badge +10

Why not use SetValueExt, and set the Project value after the Customer? Most edit screens are designed to have the Customer selected first and I believe that’s why it is clearing your Project field. I would simply set it again.

Userlevel 3
Badge +1

Okay,

The business logic between the customer and the project was too complicated to rework for me.

I found a workaround. I hid the standard Project field and replaced it with an DB unbound Project field (ProjectID2). Along with the below code I hid and unhid both fields to ensure the standard field was visible once a project was selected. I was worried that the UI would be glitchy, but it is not noticeable.

 

        protected void _(Events.FieldUpdated<SOOrder, SOOrderExt.projectID2> e)
{
if (e.Row == null) return;
SOOrder so = (SOOrder)e.Row;

if (so.CustomerID == null && e.NewValue != null)
{
var prj = PMProject.PK.Find(e.Cache.Graph, (int)e.NewValue);

e.Cache.SetValueExt<SOOrder.customerID>(e.Row, prj.CustomerID);
e.Cache.SetValueExt<SOOrder.projectID>(e.Row, prj.ContractID);

e.Cache.SetValue<SOOrderExt.projectID2>(e.Row, null);
}
}

 

Userlevel 7
Badge

Thank you for sharing your solution with the community @Leif !

Badge +10

Creative 🙂

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