Skip to main content
Solved

Custom field not getting updated


Forum|alt.badge.img

Hi. When the user inserts a line level record in the applications tab of the Invoices form I need to update one of my custom fields. I’m trying to update my custom field which is the UsrTotalCreditDue with a calculation of the values that i get from the two data views. In the code i am also printing the values to the trance. The values get updated in the trance but doesn’t update the field. How can i fix this ?

Trace Values

 

Customization Code

 

Best answer by andriitkachenko

@ifelix

  1. I meant to take my code, replace public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry> with public class SOInvoiceEntryExt : PXGraphExtension<SOInvoiceEntry>
  2. Since you want update field you added to the top form, you can use Base.Document.Current to get invoice that is selected in the top form (that’s to replace your logic to get arInvoiceHeader)

You can just compare my event with yours instead of copying everything - again, I tried to keep it similar to yours.

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

7 replies

andriitkachenko
Jr Varsity I
Forum|alt.badge.img+5

Hi @ifelix 

This should work:

    public class ARInvoiceExt : PXCacheExtension<ARInvoice>
    {
        [PXDBDecimal]
        [PXUIField(DisplayName = "Total Credit Due", Enabled = false)]
        public virtual decimal? UsrTotalCreditDue { get; set; }
        public abstract class usrTotalCreditDue : PX.Data.BQL.BqlDecimal.Field<usrTotalCreditDue> { }
    }

    public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
    {
        public PXSelectJoin<ARInvoice,
            InnerJoin<ARAdjust,
                On<ARInvoice.noteID, Equal<ARAdjust.memoID>>>,
            Where<ARAdjust.adjdRefNbr, Equal<Required<ARAdjust.adjdRefNbr>>,
                And<ARAdjust.adjdDocType, Equal<Required<ARAdjust.adjdDocType>>>>>
            ARInvoiceAdjustView;

        protected void _(Events.RowInserted<ARAdjust> e)
        {
            if(!(e.Row is ARAdjust row)) return;

            ARInvoice arInvoice = PXSelect<ARInvoice,
                Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>,
                    And<ARInvoice.docType, Equal<Required<ARInvoice.docType>>>>>
                .Select(Base, row.AdjdRefNbr, row.AdjdDocType);

            ARInvoice arInvoiceHeader = ARInvoiceAdjustView.SelectSingle(row.AdjdRefNbr, row.AdjdDocType);

            var ext = arInvoiceHeader.GetExtension<ARInvoiceExt>();
            ext.UsrTotalCreditDue = arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal;
            Base.Document.Update(arInvoiceHeader);
        }
    }

It’s mostly the same as yours. Aside from some formatting changes (which are subjective), the difference is:

  • The extension is made to the ARInvoice. ARRegister is a parent class for it, but the Acumatica uses reflection to work with all customization extensions, so it might cause issues when Cache is being handled;  
  • Calls to cache changed to use PXCache embedded into the PXView. Direct type calls can be ignored in some cases - Persist checks Caches from Views. If ARRegister and ARInvoice Caches are handled separately, this can cause issues;  
  • You are using 2 options of setting the value at the same time. There’s no point in it. You can use Base.Document.SetValueExt<ARInvoiceExt.usrTotalCreditDue>(arInvoiceHeader, arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal); instead of direct ext.UsrTotalCreditDue = arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal; but they are doing the same.

Also, take a look at your implementation of the UsrTotalCreditDue. Some attributes are able to affect the process. In my example, I decorated the field with the bare minimum of the attributes.


Forum|alt.badge.img
  • Author
  • Freshman I
  • 21 replies
  • August 8, 2024
andriitkachenko wrote:

Hi @ifelix 

This should work:

    public class ARInvoiceExt : PXCacheExtension<ARInvoice>
    {
        [PXDBDecimal]
        [PXUIField(DisplayName = "Total Credit Due", Enabled = false)]
        public virtual decimal? UsrTotalCreditDue { get; set; }
        public abstract class usrTotalCreditDue : PX.Data.BQL.BqlDecimal.Field<usrTotalCreditDue> { }
    }

    public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
    {
        public PXSelectJoin<ARInvoice,
            InnerJoin<ARAdjust,
                On<ARInvoice.noteID, Equal<ARAdjust.memoID>>>,
            Where<ARAdjust.adjdRefNbr, Equal<Required<ARAdjust.adjdRefNbr>>,
                And<ARAdjust.adjdDocType, Equal<Required<ARAdjust.adjdDocType>>>>>
            ARInvoiceAdjustView;

        protected void _(Events.RowInserted<ARAdjust> e)
        {
            if(!(e.Row is ARAdjust row)) return;

            ARInvoice arInvoice = PXSelect<ARInvoice,
                Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>,
                    And<ARInvoice.docType, Equal<Required<ARInvoice.docType>>>>>
                .Select(Base, row.AdjdRefNbr, row.AdjdDocType);

            ARInvoice arInvoiceHeader = ARInvoiceAdjustView.SelectSingle(row.AdjdRefNbr, row.AdjdDocType);

            var ext = arInvoiceHeader.GetExtension<ARInvoiceExt>();
            ext.UsrTotalCreditDue = arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal;
            Base.Document.Update(arInvoiceHeader);
        }
    }

It’s mostly the same as yours. Aside from some formatting changes (which are subjective), the difference is:

  • The extension is made to the ARInvoice. ARRegister is a parent class for it, but the Acumatica uses reflection to work with all customization extensions, so it might cause issues when Cache is being handled;  
  • Calls to cache changed to use PXCache embedded into the PXView. Direct type calls can be ignored in some cases - Persist checks Caches from Views. If ARRegister and ARInvoice Caches are handled separately, this can cause issues;  
  • You are using 2 options of setting the value at the same time. There’s no point in it. You can use Base.Document.SetValueExt<ARInvoiceExt.usrTotalCreditDue>(arInvoiceHeader, arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal); instead of direct ext.UsrTotalCreditDue = arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal; but they are doing the same.

Also, take a look at your implementation of the UsrTotalCreditDue. Some attributes are able to affect the process. In my example, I decorated the field with the bare minimum of the attributes.

Hello.

This customization is related to Sales Order Invoice. So how can i make the extension to ARInvoice ? Shouldn’t it be made to SOInvoice Entry ?

This is the extension i am using.

 

Please help. Struggling with this issue since weeks.


andriitkachenko
Jr Varsity I
Forum|alt.badge.img+5

I assumed from your first message that you’re trying to customize ARInvoiceEntry. If you need to override SOOrderEntry, you can change the base graph type in the PXGraphExtension<ARInvoiceEntry> part (renaming the graph extension to fit would be nice as well).

However, I’m confused with the part where you’re saying 

in the applications tab of the Invoices form

That doesn’t sound like you’re trying to customize Sales Orders screen. You can double-check the graph you need to customize using Inspect Element.


Forum|alt.badge.img
  • Author
  • Freshman I
  • 21 replies
  • August 8, 2024

Hi there,

What do you mean by change the base graph in PXGraphExtension<ARInvoiceEntry> part ? In my code should i change PXGraphExtension<PX.Objects.SO.SOInvoiceEntry>  to PXGraphExtension<ARInvoiceEntry>  ? Can you explain it a bit more?

Also, what i meant in the applications tab of the Invoices form is this:
 

So i already have the data i need to update this particular field. So what i want is when the user inserts a line level row in the applications tab, to update the Total Credit Due field with the data that i obtain from my data view. My issue is this field doesn’t update.


ifelix wrote:
andriitkachenko wrote:

Hi @ifelix 

This should work:

    public class ARInvoiceExt : PXCacheExtension<ARInvoice>
    {
        [PXDBDecimal]
        [PXUIField(DisplayName = "Total Credit Due", Enabled = false)]
        public virtual decimal? UsrTotalCreditDue { get; set; }
        public abstract class usrTotalCreditDue : PX.Data.BQL.BqlDecimal.Field<usrTotalCreditDue> { }
    }

    public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
    {
        public PXSelectJoin<ARInvoice,
            InnerJoin<ARAdjust,
                On<ARInvoice.noteID, Equal<ARAdjust.memoID>>>,
            Where<ARAdjust.adjdRefNbr, Equal<Required<ARAdjust.adjdRefNbr>>,
                And<ARAdjust.adjdDocType, Equal<Required<ARAdjust.adjdDocType>>>>>
            ARInvoiceAdjustView;

        protected void _(Events.RowInserted<ARAdjust> e)
        {
            if(!(e.Row is ARAdjust row)) return;

            ARInvoice arInvoice = PXSelect<ARInvoice,
                Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>,
                    And<ARInvoice.docType, Equal<Required<ARInvoice.docType>>>>>
                .Select(Base, row.AdjdRefNbr, row.AdjdDocType);

            ARInvoice arInvoiceHeader = ARInvoiceAdjustView.SelectSingle(row.AdjdRefNbr, row.AdjdDocType);

            var ext = arInvoiceHeader.GetExtension<ARInvoiceExt>();
            ext.UsrTotalCreditDue = arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal;
            Base.Document.Update(arInvoiceHeader);
        }
    }

It’s mostly the same as yours. Aside from some formatting changes (which are subjective), the difference is:

  • The extension is made to the ARInvoice. ARRegister is a parent class for it, but the Acumatica uses reflection to work with all customization extensions, so it might cause issues when Cache is being handled;  
  • Calls to cache changed to use PXCache embedded into the PXView. Direct type calls can be ignored in some cases - Persist checks Caches from Views. If ARRegister and ARInvoice Caches are handled separately, this can cause issues;  
  • You are using 2 options of setting the value at the same time. There’s no point in it. You can use Base.Document.SetValueExt<ARInvoiceExt.usrTotalCreditDue>(arInvoiceHeader, arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal); instead of direct ext.UsrTotalCreditDue = arInvoice.CuryOrigDocAmt - arInvoiceHeader.CuryDetailExtPriceTotal; but they are doing the same.

Also, take a look at your implementation of the UsrTotalCreditDue. Some attributes are able to affect the process. In my example, I decorated the field with the bare minimum of the attributes.

Hello.

This customization is related to Sales Order Invoice. So how can i make the extension to ARInvoice ? Shouldn’t it be made to SOInvoice Entry ?

This is the extension i am using.

 

Please help. Struggling with this issue since weeks.

 


Hi @ifelix,

Do you have

public static bool IsActive() => true;

in your DAC extension?


andriitkachenko
Jr Varsity I
Forum|alt.badge.img+5

@ifelix

  1. I meant to take my code, replace public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry> with public class SOInvoiceEntryExt : PXGraphExtension<SOInvoiceEntry>
  2. Since you want update field you added to the top form, you can use Base.Document.Current to get invoice that is selected in the top form (that’s to replace your logic to get arInvoiceHeader)

You can just compare my event with yours instead of copying everything - again, I tried to keep it similar to yours.


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