Follow-up question from my previous question Make a Field Mandatory on the Graph Level.
After applying the answer from my previous question by removing the underscore (_
) from my TableColumn, it is obvious that the Customer Locations screen is now picking up on the code customizations, so I accepted the answer there, as my new issue is sure to require a different solution.
Upon loading the Customer Locations (AR303020) screen, I am now receiving this error:
Failed to subscribe the event PX.Objects.AR.CustomerLocationMaint_Extension::SelectedCustomerLocation_UsrDCLID_CacheAttached in the graph PX.Objects.AR.CustomerLocationMaint. The method signature looks like an event handler, but the cache SelectedCustomerLocation has not been found in the list of auto-initialized caches. Remove unused event handlers from the code.
I used the OVERRIDE ON SCREEN LEVEL button from the Layout Editor to generate what I would assume to be the correct code stub.
This is the stock code produced:
using System;
using PX.Data;
using PX.Objects.CR;
using System.Collections.Generic;
using PX.Objects;
using PX.Objects.AR;
namespace PX.Objects.AR
{
public class CustomerLocationMaint_Extension : PXGraphExtension<CustomerLocationMaint>
{
#region Event Handlers
protected virtual void SelectedCustomerLocation_UsrDCLID_CacheAttached(PXCache cache)
{
}
#endregion
}
}
And this is after my simple Required modifications:
using System;
using PX.Data;
using PX.Objects.CR;
using System.Collections.Generic;
using PX.Objects;
using PX.Objects.AR;
namespace PX.Objects.AR
{
public class CustomerLocationMaint_Extension : PXGraphExtension<CustomerLocationMaint>
{
#region Event Handlers
[PXDefault]
[PXCustomizeBaseAttribute(typeof(PXUIFieldAttribute), "Required", true)]
protected virtual void SelectedCustomerLocation_UsrDCLID_CacheAttached(PXCache cache)
{
}
#endregion
}
}
From here I save my code changes and publish the Customization Project. Then, when I refresh the Customer Locations screen, I receive the aforementioned error.
You can see here that the Data Class for this form is PX.Objects.AR.SelectedCustomerLocation
But when I inspect the field on the page, it shows the Data Class is Location
, which I've found correlates to PX.Objects.CR.Location
. I believe the AR.SelectedCustomerLocation
extends CR.Location
I'm not really sure where to go from here. Given that the system generated the SelectedCustomerLocation_UsrDCLID_CacheAttached
method then I have to believe this is the event handler that is needed. I have tried changing this to Location_UsrDCLID_CacheAttached
, which causes the error to go away, but the Requiredness of the field is not there, so I do not believe this is the correct method signature.
How do I get the SelectedCustomerLocation cache to exist on this page? Do I need it to exist? Should it just be Location?
Location_UsrDCLID_CacheAttached would be correct name as you use the base DAC name for which you are extending. SelectedCustomerLocation inherits from SelectedLocation which inherits from Location.
Try this...
[PXDBInt]
[PXUIField(DisplayName="DCL Account ID", Required = true)]
protected virtual void Location_UsrDCLID_CacheAttached(PXCache cache)
{
}
You can add the PXUIRequiredAttribute
if you need a conditional requirement. Example:
[PXUIRequired(typeof(Where<INItemSite.overrideInvtAcctSub, Equal<True>>))]
You can use PXUIFieldAttribute to set the required property on the DAC, Graph cached attached, or in logic such as the RowSelected event or a graph extension initialization.
Example:
protected virtual void Location_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
PXUIFieldAttribute.SetRequired<LocationExt.usrDCLID>(cache, true);
}
For more flexibility you can check for the condition in the rowpersisting event like so...
protected virtual void Location_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
var row = (Location)e.Row;
if(row == null)
{
return;
}
var rowExt = row.GetExtension<LocationExt>();
if (rowExt != null && rowExt.UsrDCLID == null)
{
if (sender.RaiseExceptionHandling<LocationExt.usrDCLID>(e.Row, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, typeof(LocationExt.usrDCLID).Name)))
{
throw new PXRowPersistingException(typeof(LocationExt.usrDCLID).Name, null, ErrorMessages.FieldIsEmpty, typeof(LocationExt.usrDCLID).Name);
}
}
}