Skip to main content
Solved

PXUIVerify not working


Joe Schmucker
Captain II
Forum|alt.badge.img+2

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
[PXDBString(3, IsFixed = true, IsKey = true, InputMask = "###")]
[PXUIField(DisplayName = "Lower")]
[PXUIVerify(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.

 

 

Best answer by Joe Schmucker

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!

View original
Did this topic help you find an answer to your question?

4 replies

Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 455 replies
  • June 21, 2024

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:

 


Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 455 replies
  • Answer
  • June 23, 2024

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!


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3409 replies
  • June 24, 2024

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


Joe Schmucker
Captain II
Forum|alt.badge.img+2
  • Author
  • Captain II
  • 455 replies
  • June 24, 2024

@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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings