We have a custom field that we’ve added to a page and the client wants to make it required, but only require it based on the company they are in. So it would not be required if they are in Company A, Company B, or Company C but it would be required if they are in Company D. Is there an easy way to accomplish something like this?
Solved
Make a field required but only in one company
Best answer by Django
The RowSelected event will work perfectly for this. You can decide how you want to determine the logic for making the field required/not required and call this. I’d be tempted to add a field to the relevant Preferences screen that toggles this behaviour on and off. That way if they add a new company, you don’t need to recompile anything - just check, or uncheck a box.
protected virtual void _(Events.RowSelected<SOOrder> e, PXRowSelected baseHandler)
{
baseHandler?.Invoke(e.Cache, e.Args);
SOOrder row = e.Row as SOOrder;
if (row == null) return;
bool flagVariable = MethodUsedToDetermineRequiredOrNot();
PXUIFieldAttribute.SetRequired<SOOrder.usrYourField>(e.Cache, flagVariable);
}
I also have this method that I found within the Acumatica code that I use to check to make sure that all required fields have been filled so I can control that better:
if (CheckRequiredFieldsFilled(Base.Document.Cache, row) == false)
{
PopupNoteManager.RegisterText(Base.Document.Cache, row, "OrderNbr", "Please enter the missing field data.");
}
private static bool CheckRequiredFieldsFilled(PXCache aCache, IBqlTable aFilter)
{
bool allFilled = true;
foreach (var field in aCache.BqlFields)
{
PXFieldState state = aCache.GetStateExt(aFilter, field.Name) as PXFieldState;
if (state != null)
{
object value = aCache.GetValue(aFilter, field.Name);
if (state.Required == true && value == null)
{
aCache.RaiseExceptionHandling(field.Name, aFilter, null,
new PXSetPropertyException(Messages.RequiredField));
allFilled = false;
}
}
}
return allFilled;
}
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.