Solved

Require one record in grid added before saving parent

  • 25 April 2024
  • 3 replies
  • 37 views

So normally when you want to require a field that’s a fairly simple task. But what can you do when you want to require a record to exist in a detail grid? For example, on the Customer maintenance page there is a SalesPersons tab. I want to make sure at least one record is in that grid before allowing the customer to save. Is that an easy task? I didn’t see anything in the grid properties that would make sense and figure it will likely have to be done with a graph extension, but not sure how to go about it.

 

For example, there is no salesperson record saved here so saving the customer should result in an error:

 

Thanks for any recommendations or tips!

icon

Best answer by Vignesh Ponnusamy 25 April 2024, 22:37

View original

3 replies

Userlevel 7
Badge +4

Hi @mmarklow44,

Yes you are right, you should be able to do it from the graph extension. You can override the Persist method in which you can check if there is at least one entry in the SalesPersons view then raise exception to if there are no entries in the view. Below is an example implementation you can start with,

    public class CustomerMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerMaint>
{
//const string salesPersonException = "Please Add atlease One Sales Person";
#region Event Handlers
public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate baseMethod)
{
if (Base.SalesPersons.Select().Count == 0)
{
throw new PXSetPropertyException("Please Add atlease One Sales Person", PXErrorLevel.RowError);
}
baseMethod();
}
#endregion
}

Good Luck,

Perfect, that’s exactly what I was looking for. It makes sense, it’s just that being new to Acumatica a bit sometimes I don’t always know which events to override depending on what you’re doing but that helps.

Thanks again!

Userlevel 7
Badge +4

Hi @mmarklow44,

Yes, there are good help resources about event handler you can refer to. For example, you can check the following article that demonstrates when the event handlers will be triggered, https://help.acumatica.com/(W(4))/Help?ScreenId=ShowWiki&pageid=d9cf6274-f5c8-43e7-9d13-9b423113d67e

Quick tip, when you are within the customization project you can navigate to the Events tab and select a event handler then see the tool tip below the grid,

This can initially help you to choose the right event handler for a specific scenario. Happy Development.! 

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