Skip to main content
Solved

User input disappearing on trying to save.


Michael Ndungi
Varsity I
Forum|alt.badge.img

Hello everyone, I created a table with the following script.

CREATE TABLE [dbo].[GDLFAVehicleDetails](
	[CompanyId] [int] NOT NULL,
	[AssetId] [int] NOT NULL,
	[VehicleRegNo] [nvarchar](50) NOT NULL,
	/***other fields left out***/

 CONSTRAINT [PK_GDLFAVehicleDetails] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC,
	[AssetId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_GDLFAVehicleDetails_1] UNIQUE NONCLUSTERED 
(
	[VehicleRegNo] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

I needed to make VehicleRegNo to accept only unique values
so I added Iskey= true on the DAC as shown below;
However when I add the Iskey=true value the user input disappears, when I remove it user input does not disappear on the UI and user is able to save the input entered.

What could be the issue?

 

   #region VehicleRegNo
        [PXDBString(50,IsKey =true, IsUnicode = true)]
        [PXDefault]
        [PXUIField(DisplayName = "Vehicle Reg No.")]
        public virtual string VehicleRegNo { get; set; }

        public abstract class vehicleRegNo : PX.Data.BQL.BqlString.Field<vehicleRegNo>
        {
        }
        #endregion

Kindly asist
Any kind of response will be highly appreciated.

Best answer by Joe Schmucker

@Michael Ndungi 

I would remove the constraint for VehicleRegNo in the SQL table and just use [PXCheckUnique].  That has worked for me.  The other option would be to add VehicleRegNo to the primary key.  I don’t see why you would need a separate constraint for that field.  Based on your description, the combination of AssetId and VehicleRegNo should always be unique.  If you do that, you wouldn’t need to use [PXCheckUnique].  However, using [PXCheckUnique] allows you to provide a nice message if they try to save a duplicate.  [PXCheckUnique(typeof(VehicleRegNo ), ErrorMessage = "My message")]

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

2 replies

andriikravetskyi35
Jr Varsity I
Forum|alt.badge.img+1

Hi Michael,

I remember two unique attributes that Acumatica allow to use in DAC:

[PXUnique]
[PXCheckUnique]

 

Try it, I guess that first attribute will help you.


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Captain II
  • 443 replies
  • Answer
  • August 14, 2023

@Michael Ndungi 

I would remove the constraint for VehicleRegNo in the SQL table and just use [PXCheckUnique].  That has worked for me.  The other option would be to add VehicleRegNo to the primary key.  I don’t see why you would need a separate constraint for that field.  Based on your description, the combination of AssetId and VehicleRegNo should always be unique.  If you do that, you wouldn’t need to use [PXCheckUnique].  However, using [PXCheckUnique] allows you to provide a nice message if they try to save a duplicate.  [PXCheckUnique(typeof(VehicleRegNo ), ErrorMessage = "My message")]


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