Skip to main content
Answer

Make conditionally visible custom field required

  • June 8, 2023
  • 6 replies
  • 924 views

rcreasy
Varsity I
Forum|alt.badge.img

I am attempting to make a custom field on a sales order required. This custom field is only visible when OrderType is “NC”.

I am struggling with how to determine if the field is visible and if it is null or blank.
I have tried several different methods I have found from various sources. The code below is totally wrong… but is where I got to the point of asking for help…. This code is in my DAC extension.
 
 

        protected void _(Events.RowPersisting<SOOrderExt> e)
{
var isVisible = SOOrder.orderType.IsEqual<ncOrder>;
if (BqlString.Field<usrNoChargeDept> == null && isVisible) {
throw new PXException(Messages.RequiredNCDept);
}
}

 ncOrder is:

  public class ncOrder : PX.Data.BQL.BqlString.Constant<ncOrder>
{
public ncOrder() : base("NC") { }
}

RequiredNCDept is a string in a file with other messages.

I attempted the solution here: 

But ran into the issue of finding when the field is visible.

How can I make the field required only when visible?

Best answer by darylbowman

Is this question related to this one?

If this is the same field and you want to conditionally make the field visible AND make it required when it’s visible, you can use PXUIRequired on the DAC field in the same way as PXUIVisible, like this:

#region CustomField
[PXDBString(IsUnicode = true, InputMask = "")]
[PXUIVisible(typeof(Where<SOOrder.orderType.IsEqual<ncOrder>>))]
[PXUIRequired(typeof(Where<SOOrder.orderType.IsEqual<ncOrder>>))]
[PXUIField(DisplayName = "Custom Field")]
public virtual string CustomField { get; set; }
public abstract class customField : PX.Data.BQL.BqlString.Field<customField> { }
#endregion

 

6 replies

Forum|alt.badge.img+7
  • Captain II
  • June 8, 2023

You want to put this in RowSelected most of the time.

PXUIFieldAttribute.SetVisible<TheDAC.theField>(cache, row, true_or_false);


rcreasy
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • June 8, 2023

@Django Thank you. That line only sets visibility, right? How do I then read/get the visibility? And, then use the visibility to set required/not required?


Forum|alt.badge.img+7
  • Captain II
  • June 8, 2023

Yes, that only does the visibility.

Is the challenge that you don’t know if the field is visible or not when you’re in the RowPersisting event? In theory you should have full access to the record’s fields to determine if the criteria has been met for the fields visible/hidden state and you can test for the same condition.

 


darylbowman
Captain II
Forum|alt.badge.img+15

Is this question related to this one?

If this is the same field and you want to conditionally make the field visible AND make it required when it’s visible, you can use PXUIRequired on the DAC field in the same way as PXUIVisible, like this:

#region CustomField
[PXDBString(IsUnicode = true, InputMask = "")]
[PXUIVisible(typeof(Where<SOOrder.orderType.IsEqual<ncOrder>>))]
[PXUIRequired(typeof(Where<SOOrder.orderType.IsEqual<ncOrder>>))]
[PXUIField(DisplayName = "Custom Field")]
public virtual string CustomField { get; set; }
public abstract class customField : PX.Data.BQL.BqlString.Field<customField> { }
#endregion

 


rcreasy
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • June 8, 2023

@darylbowman :-) yes - related, same project.
 Thank you again my friend! I did have to add [PXDefault]  to the field (I had removed it because it caused the field to be required when hidden)

I REALLY appreciate your help. Thanks so much!
 

Is there somewhere I can find these attributes(not sure what to call them?)?


darylbowman
Captain II
Forum|alt.badge.img+15

There may be, but I learned them by seeing other code where people used them. They are remarkably useful. Worlds easier in many cases, than having to define an event just to do the simple things.

 

The third musketeer is PXUIEnabled. Works exactly the same as the other two.