Skip to main content
Solved

PXUIVerify not working

  • 21 June 2024
  • 4 replies
  • 41 views

EDIT: partially fixed the issue - see my next post for the “new” issue.

I have a 3 digit fixed length field on my grid. I want to ensure that the value entered is 3 characters exactly.

I used a PXUIVerify to ensure the length of the value in the field is 3 characters.

#region Lower
rPXDBString(3, IsFixed = true, IsKey = true, InputMask = "###")]
rPXUIField(DisplayName = "Lower")]
oPXUIVerify(typeof(Where<Length<ICSFSSScheduleLine.lower>, Less<Length3>>), PXErrorLevel.Error, ICSMessages.ZipIsNotANumber, typeof(string))]
public virtual string Lower { get; set; }
public abstract class lower : PX.Data.BQL.BqlString.Field<lower> { }
#endregion

Here is the definition for “Length3”:

    public static class ICSConstants
    {
        public const int Length3 = 3;
    }

    public class Length3 : PX.Data.BQL.BqlInt.Constant<Length3>
    {
        public Length3() : base(ICSConstants.Length3)
        {
        }
    }

If you enter 010 (which is valid), you still get an error:

I could try using FieldVerifying on the field, but I think it is much better to handle this at the DAC level.  I don’t see why my code is not working.

 

 

Dang.  I just figured out that the Verify fires an error if the validation is FALSE.  I changed Less to Equals and that gets rid of the error.

However, I still have a problem.  If you enter “02”, it still sees the value in the field as 3 characters.  I think it is because the field definition is IsFixed = true and the DB field is CHAR(3).

In my DAC, I changed the declaration from IsFixed = true to IsUnicode = true.  If you enter “02”, you now get the correct error message.  However, if you edit the field and enter “020” and leave the field, you do not get an error message.  But when you click Save, the value in the field reverts back to “02” and you get the error message again:

 


I found what was causing the error.  When I enter an bad value in the field, it was being added to the cache (with a bad value).  Since this is a Key Field, when I corrected the value, it added another record to the cache and left the old record in the cache.  I put validation in the RowInserting handler with e.Cancel = true if there is a problem with the record.  This prevents the bad record from getting added to the cache.

I guess I just needed a good night’s sleep and a fresh set of eyes.

If anyone finds this post in the future, if you have a Key Field that is allowed to be edited, be sure invalid data is NOT added to the cache.  Or, you will waste a lot of time like I did!


@Joe Schmucker  Did this works for you after removing Is Key = true?


@Naveen Boga , I cannot remove the iskey=true from the DAC because it is a key field. By validating the record and cancelling it from being added to the cache in the RowInserting handler, I am able to stop it from being added to the cache, and now you can edit it to correct the field.

I’ve never done a maintenance screen that had a key field in the grid that could be modified.  This one was a bit tricky.  In fact, 4 of the 5 fields in the grid are key fields.  Sometimes it is the simplest looking screens that are the hardest to program.


Reply