Solved

When I click + to get a new record, the first field is not being cleared (cache not cleared?)

  • 22 June 2022
  • 3 replies
  • 136 views

Userlevel 6
Badge +3

I have a form with two selector fields.  I want to store the two values in a custom table.  The selector fields work and I can select values and save the record.  But when I click + to create a new record, the first field still contains the previously saved value.  I THINK that the cache is not being cleared when I click +.

This is the form after selecting values:

Click Save and the record saves.

After clicking +

If I lookup a value (any value) for the service type field and click save, I get

 

If I click Refresh on the browser, I get a clean screen that will let me add a new record.

Note that if I navigate to existing records and make changes, they do get saved properly.

Is there some hack I can do to clear the cache when I click the + ?

 

The graph only contains one thing, the view:

	public class SSGCRRecordServiceTypeLinks : PXGraph<SSGCRRecordServiceTypeLinks, SSGCRServTypeRecTypeXR>
{

public SelectFrom<SSGCRServTypeRecTypeXR>.View ServTypeRecTypeLinks;

This is the DAC for the table:

	[Serializable]
[PXCacheName("Record Type / Service Type XR")]
public class SSGCRServTypeRecTypeXR : IBqlTable
{

#region ID
[PXDBIdentity]
public virtual int? ID { get; set; }
public abstract class iD : PX.Data.BQL.BqlInt.Field<iD> { }
#endregion

#region RecordTypeID
[PXDBInt(IsKey = true)]
[PXDefault]
[PXUIField(DisplayName = "Record Type")]
[PXSelector(typeof(Search<SSGCRRecordType.recordTypeID>),
typeof(SSGCRRecordType.recordTypeCD),
typeof(SSGCRRecordType.description),
typeof(SSGCRRecordType.isActive),
SubstituteKey = typeof(SSGCRRecordType.recordTypeCD),
DescriptionField = typeof(SSGCRRecordType.description))]
public virtual int? RecordTypeID { get; set; }
public abstract class recordTypeID : PX.Data.BQL.BqlInt.Field<recordTypeID> { }
#endregion

#region ServiceTypeID
[PXDBInt(IsKey = true)]
[PXDefault]
[PXUIField(DisplayName = "Service Type")]
[PXSelector(typeof(Search<SSGCRServiceType.serviceTypeID>),
typeof(SSGCRServiceType.serviceTypeCD),
typeof(SSGCRServiceType.description),
typeof(SSGCRServiceType.isActive),
SubstituteKey = typeof(SSGCRServiceType.serviceTypeCD),
DescriptionField = typeof(SSGCRServiceType.description))]
public virtual int? ServiceTypeID { get; set; }
public abstract class serviceTypeID : PX.Data.BQL.BqlInt.Field<serviceTypeID> { }
#endregion

#region IsActive
[PXDBBool()]
[PXDefault(true)]
[PXUIField(DisplayName = "Active")]
public virtual bool? IsActive { get; set; }
public abstract class isActive : PX.Data.BQL.BqlBool.Field<isActive> { }
#endregion

#region CreatedByID
[PXDBCreatedByID()]
public virtual Guid? CreatedByID { get; set; }
public abstract class createdByID : PX.Data.BQL.BqlGuid.Field<createdByID> { }
#endregion

#region CreatedByScreenID
[PXDBCreatedByScreenID()]
public virtual string CreatedByScreenID { get; set; }
public abstract class createdByScreenID : PX.Data.BQL.BqlString.Field<createdByScreenID> { }
#endregion

#region CreatedDateTime
[PXDBCreatedDateTime()]
public virtual DateTime? CreatedDateTime { get; set; }
public abstract class createdDateTime : PX.Data.BQL.BqlDateTime.Field<createdDateTime> { }
#endregion

#region LastModifiedByID
[PXDBLastModifiedByID()]
public virtual Guid? LastModifiedByID { get; set; }
public abstract class lastModifiedByID : PX.Data.BQL.BqlGuid.Field<lastModifiedByID> { }
#endregion

#region LastModifiedByScreenID
[PXDBLastModifiedByScreenID()]
public virtual string LastModifiedByScreenID { get; set; }
public abstract class lastModifiedByScreenID : PX.Data.BQL.BqlString.Field<lastModifiedByScreenID> { }
#endregion

#region LastModifiedDateTime
[PXDBLastModifiedDateTime()]
public virtual DateTime? LastModifiedDateTime { get; set; }
public abstract class lastModifiedDateTime : PX.Data.BQL.BqlDateTime.Field<lastModifiedDateTime> { }
#endregion

#region Tstamp
[PXDBTimestamp()]
public virtual byte[] Tstamp { get; set; }
public abstract class tstamp : PX.Data.BQL.BqlByteArray.Field<tstamp> { }
#endregion

#region Noteid
[PXNote()]
public virtual Guid? Noteid { get; set; }
public abstract class noteid : PX.Data.BQL.BqlGuid.Field<noteid> { }
#endregion

This is the table in SQL:

CREATE TABLE [dbo].[SSGCRServTypeRecTypeXR](
[CompanyID] [int] NOT NULL,
[id] [int] IDENTITY(1,1) NOT NULL,
[RecordTypeID] INT NOT NULL,
[ServiceTypeID] INT NOT NULL,
[IsActive] [bit] NULL,
[CreatedByID] [uniqueidentifier] NOT NULL,
[CreatedByScreenID] [char](8) NOT NULL,
[CreatedDateTime] [datetime] NOT NULL,
[LastModifiedByID] [uniqueidentifier] NOT NULL,
[LastModifiedByScreenID] [char](8) NOT NULL,
[LastModifiedDateTime] [datetime] NOT NULL,
[tstamp] [timestamp] NOT NULL,
[NoteID] [uniqueidentifier] NULL,
CONSTRAINT [SSGCRServTypeRecTypeXR_PK] PRIMARY KEY CLUSTERED
(
[CompanyID] ASC,
--[id] ASC
[RecordTypeID]ASC,
[ServiceTypeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [primary]
) ON [primary]
GO

 

 

icon

Best answer by Leonardo Justiniano 22 June 2022, 23:26

View original

3 replies

Userlevel 6
Badge +4

Hi @joe21 

 

[PXDefault(true)] should be it. Please look at the field layout properties. Maybe a wrong setting.

 

Glad to help!

Userlevel 6
Badge +3

Hi @Leonardo Justiniano 

Mindboggling.  By making the changes you suggested, it fixed the problem.  The ID field is an identity field in the table.  I have a constraint on the table for the Companyid, RecordTypeID and ServiceTypeID fields.  It would seem intuitive that the RecordTypeID and ServiceTypeID fields should be marked as IsKey = true.  Does that mean that we just rely on SQL constraints to keep from inserting duplicates?

The only other strange thing (at least right now :-)) is that when I click new, the Active checkbox is not checked.  When the record saves, it saves with Active as 1 in the DB.  As soon as you click save, the check box is checked (probably because it is redisplaying the current record with the value from the DB).

Is there something wrong with this field in my DAC?

        #region IsActive
        [PXDBBool()]
        [PXDefault(true)]
        [PXUIField(DisplayName = "Active")]
        public virtual bool? IsActive { get; set; }
        public abstract class isActive : PX.Data.BQL.BqlBool.Field<isActive> { }
        #endregion
When you click new, the cache is apparently setting that field value to true but the display on the screen is not showing as checked.  

EDIT: this seems to fix the Active checkbox, but seems unecessary

        protected virtual void _(Events.RowInserted<SSGCRServTypeRecTypeXR> e)
        {
            var row = (SSGCRServTypeRecTypeXR)e.Row;
            if (row == null) return;
            row.IsActive = true;
        }
 

 

Thank you for the fix!  I spent hours trying to figure this out.

 

Userlevel 6
Badge +4

Hi @joe21 

 

The only key of the record is your identity column ID. Please set is as

[PXDBIdentity(IsKey = true)]

 

Remove the attribute IsKey from the other columns.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved