Question

Update UI Fields by Field Updated event

  • 5 October 2023
  • 9 replies
  • 201 views

Userlevel 3
Badge

Hi Team, 

I need to add the exiting database values to controls after selecting the particular vendor. I wrote some code and it is not working it clears the all controls. Can someone help me out?

 protected void _(Events.FieldUpdated<HMRCVendorRegisterDetail, HMRCVendorRegisterDetail.bAccountID> e)
        {
            HMRCVendorRegisterDetail row = e.Row;

            if (row.BAccountID != null && row.BAccountID > 0)
            {                
                HMRCVendorRegisterDetail vendorDetail = PXSelectReadonly<HMRCVendorRegisterDetail,
                       Where<HMRCVendorRegisterDetail.bAccountID, Equal<Required<HMRCVendorRegisterDetail.bAccountID>>>>.
                       Select(this, row.BAccountID);
                
                VendorRegisterDetail.Current = vendorDetail;

                //VendorRegisterDetail.Current.Hmrcregid= vendorDetail.Hmrcregid;
                //VendorRegisterDetail.Current.Active = vendorDetail.Active;
                //VendorRegisterDetail.Current.HMRCVendorVerified = vendorDetail.HMRCVendorVerified;
                //VendorRegisterDetail.Current.HMRCVendorPrecentage = vendorDetail.HMRCVendorPrecentage;
                //VendorRegisterDetail.Current.HMRCVendorRegTypeID = vendorDetail.HMRCVendorRegTypeID;
                //VendorRegisterDetail.Current.ValidFrom = vendorDetail.ValidFrom;
                //VendorRegisterDetail.Current.ValidTo = vendorDetail.ValidTo;
                //VendorRegisterDetail.Current.VerifiedDate = vendorDetail.VerifiedDate;
                //VendorRegisterDetail.Current.Utrno = vendorDetail.Utrno;
                //VendorRegisterDetail.Current.VerificationResult = vendorDetail.VerificationResult;
                //VendorRegisterDetail.Current.VerifiedTypeID = vendorDetail.VerifiedTypeID;
                //VendorRegisterDetail.Current.VerificationNote = vendorDetail.VerificationNote;
            }            
        }

 


9 replies

Userlevel 7
Badge +4

@bhagyat25 have you had a chance to review suggestion @ c# - How to determine the correct way to update a DAC field? - Stack Overflow

From Framework guide:

To modify field values in a FieldUpdated event handler, follow the rules below:
• To update a field that is defined after the current field in the data access class, use the properties of the e.Row data record as shown in the following code example.
    ShipmentLine line = e.Row as ShipmentLine;
    ...
    line.Description = product.ProductName;

    Direct assignment of a value sets it to the given instance of the data record; no field-level events are raised at this point.
• To update a field that is defined before the current field in the data access class, use one of the following
methods:
    • SetValueExt<>(): You use this method of the cache to assign a specific value to a field. The method raises the same field-level events for the data field as the events raised when a data record is updated.

    • SetDefaultExt<>(): You use this method of the cache to assign the default value to a field. The method raises the same field-level events for the data field as the events raised when a data record is inserted. For details about the insertion of a data record, see Insertion of a Data Record.

    The code example below shows an invocation of the SetValueExt<> method.
    sender.SetValueExt<ShipmentLine.ProductID>(e.Row, GiftCardID);

 

I would suggest trying something like:

row.Hmrcregid= vendorDetail.Hmrcregid;

row.Active = vendorDetail.Active;

..

..

so no

Userlevel 7
Badge +11

Hi @bhagyat25 ,

You can update the values directly with the row object like below. No need to assign the current object again. 

protected void _(Events.FieldUpdated<HMRCVendorRegisterDetail, HMRCVendorRegisterDetail.bAccountID> e)
        {
            HMRCVendorRegisterDetail row = e.Row;

            if (row.BAccountID != null && row.BAccountID > 0)
            {  
                   row.Active = true;
 }       
}    

Userlevel 3
Badge

Hi @RohitRattan88 ,

I tried with e.Cache.SetValueExt<HMRCVendorRegisterDetail.hmrcregid>(row, vendorDetail.Hmrcregid) and now fields are populating with database values. But when I press Save button it saved same record again how to do update existing instead of new record save?

Userlevel 7
Badge +4

@bhagyat25 

Please share your DAC definition. Are key fields defined properly in the DAC?

Userlevel 3
Badge

@RohitRattan88 , 

This is my DAC and HMRCregid is the primary key of the underlying table.

  #region Hmrcregid
        [PXDBIdentity(IsKey = true)]
        public virtual int? Hmrcregid { get; set; }
        public abstract class hmrcregid : PX.Data.BQL.BqlInt.Field<hmrcregid> { }
        #endregion

        #region VendorID       
        [PXUIField(DisplayName = "Vendor", Required = true)]
        [PXDBInt]
        //[PXDBIntDefault(typeof(BAccount.bAccountID))]
        [PXSelector(typeof(Search<BAccount.bAccountID, Where<BAccount.type, Equal<BAccountType.vendorType>>>),
                    typeof(BAccount.acctCD),
                    typeof(BAccount.acctName),

        SubstituteKey = typeof(BAccount.acctCD),
        DescriptionField = typeof(BAccount.acctName))]
        public virtual int? BAccountID { get; set; }
        public abstract class bAccountID : PX.Data.BQL.BqlInt.Field<bAccountID> { }
        #endregion
       
        #region Utrno
        [PXDBString(256, IsUnicode = true, InputMask = "")]
        [PXUIField(DisplayName = "UTR No", Required = true)]
        public virtual string Utrno { get; set; }
        public abstract class utrno : PX.Data.BQL.BqlString.Field<utrno> { }
        #endregion

        #region VerificationNo
        [PXDBString(256, IsUnicode = true, InputMask = "")]
        [PXUIField(DisplayName = "Verification No")]
        public virtual string VerificationNo { get; set; }
        public abstract class verificationNo : PX.Data.BQL.BqlString.Field<verificationNo> { }
        #endregion

        #region VerifiedDate
        [PXDBDate()]
        [PXUIField(DisplayName = "Verified Date")]
        [PXDefault(typeof(AccessInfo.businessDate))]
        public virtual DateTime? VerifiedDate { get; set; }
        public abstract class verifiedDate : PX.Data.BQL.BqlDateTime.Field<verifiedDate> { }
        #endregion

        #region VerifiedTypeID
        [PXDBString(1, IsFixed = true)]
        [PXDefault(RegisterTypes.System)]
        [PXUIField(DisplayName = "Verification Method")]
        [PXStringList(
        new string[]
        {
             RegisterTypes.System,
             RegisterTypes.Manual
        },
        new string[]
        {
            Messages.System, Messages.Manual
        })]
        public virtual string VerifiedTypeID { get; set; }
        public abstract class verifiedTypeID : PX.Data.BQL.BqlString.Field<verifiedTypeID> { }
        #endregion
       
        #region VerificationNote
        [PXDBString(500, IsUnicode = true, InputMask = "")]
        [PXUIField(DisplayName = "Verification Note")]
        public virtual string VerificationNote { get; set; }
        public abstract class verificationNote : PX.Data.BQL.BqlString.Field<verificationNote> { }
        #endregion

        #region VerificationResult
        [PXDBString(IsUnicode = true, InputMask = "")]
        [PXUIField(DisplayName = "Verification Result")]
        public virtual string VerificationResult { get; set; }
        public abstract class verificationResult : PX.Data.BQL.BqlString.Field<verificationResult> { }
        #endregion

        #region ValidFrom
        [PXDBDate()]
        [PXUIField(DisplayName = "Valid From")]
        [PXDefault(typeof(AccessInfo.businessDate))]
        public virtual DateTime? ValidFrom { get; set; }
        public abstract class validFrom : PX.Data.BQL.BqlDateTime.Field<validFrom> { }
        #endregion

        #region ValidTo
        [PXDBDate()]
        [PXUIField(DisplayName = "Valid To")]
        [PXDefault(typeof(AccessInfo.businessDate))]
        public virtual DateTime? ValidTo { get; set; }
        public abstract class validTo : PX.Data.BQL.BqlDateTime.Field<validTo> { }
        #endregion

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

        #region HMRCVendorRegTypeID
        [PXDBString(2, IsFixed = true)]       
        [PXUIField(DisplayName = "HMRC Vendor Reg Type")]
        [PXStringList(
        new string[]
        {
             VendorTypes.Gross,
             VendorTypes.Net,
             VendorTypes.UnRegistered
        },
        new string[]
        {
            Messages.Gross, Messages.Net, Messages.UnRegistered
        })]
        public virtual string HMRCVendorRegTypeID { get; set; }
        public abstract class hMRCVendorRegTypeID : PX.Data.BQL.BqlString.Field<hMRCVendorRegTypeID> { }
        #endregion

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

        #region VendorPrecentage
        [PXDBDecimal()]
        [PXUIField(DisplayName = "Vendor Precentage")]        
        public virtual decimal? HMRCVendorPrecentage { get; set; }
        public abstract class hMRCVendorPrecentage : PX.Data.BQL.BqlDecimal.Field<hMRCVendorPrecentage> { }
        #endregion

Userlevel 7
Badge +4

@bhagyat25 

Dont see anything wrong with the DAC, does your SQL table has proper IDs defined?

Userlevel 3
Badge

Yes 

 

Userlevel 7
Badge +4

@bhagyat25, Can you please share the customization package using which we could reproduce the behavior and troubleshoot further?

Userlevel 3
Badge

Hi @Vignesh Ponnusamy ,

Here is the customization package.

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