0

I am updating the Notes on a Bill via some custom code in a graph extension. My problem is that the window that pops open when you click on the Notes icon in the upper-right corner of the screen does not reflect the changes that I made to the notes in code. If I use the < > buttons to scroll to another Bill and then back to the one that I updated, it shows the changes. So, I'm not sure how to get the notes to refresh.

This is on the AP301000 screen. I have tried Base.Document.View.RequestRefresh(), Base.Document.View.Clear() and calling the Base.Actions.PressSave() after my code changes the note for the Bill.

TIA!

Here's Code:

protected void APTran_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
    {

        var row = (APTran)e.Row;
        if (row == null)
            return;

        //*********************** copy notes and file attachments from PO lines and header to the Bill **********************************
        if ((row.PONbr != null) && (row.POLineNbr != null))
        {
            POOrderEntry poEntry = (POOrderEntry)PXGraph.CreateInstance(typeof(POOrderEntry));
            poEntry.Clear();
            POOrder poHeader = poEntry.Document.Search<POOrder.orderNbr>(row.PONbr);
            poEntry.Document.Current = poHeader;
            POLine poLine = poEntry.Transactions.Search<POLine.lineNbr>(row.POLineNbr);

            if (poLine != null)
            {
                PXNoteAttribute.CopyNoteAndFiles(poEntry.Caches[typeof(POLine)], poLine, cache, row); //// - use this for Notes and Files.

                // making of copy of what the note is on the APInvoice at this point because the PXNoteAttribute.CopyNoteAndFiles() below
                // will replace what is in the notes with what is in the PO instead of appending.
                string oldNote = PXNoteAttribute.GetNote(Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current);

                PXNoteAttribute.CopyNoteAndFiles(poEntry.Caches[typeof(POOrder)], poHeader, Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current);
                PXNoteAttribute.SetNote(Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current, oldNote);

                Base.Actions.PressSave();

                string poNote = PXNoteAttribute.GetNote(poEntry.Caches[typeof(POOrder)], poHeader);
                if (!string.IsNullOrEmpty(poNote))
                {
                    //string oldNote = PXNoteAttribute.GetNote(Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current);
                    if ((oldNote == null) || !oldNote.Contains(poNote))
                    {
                        string newNote = "";

                        if (string.IsNullOrEmpty(oldNote))
                            newNote = poNote;
                        else
                            newNote = oldNote + Environment.NewLine + poNote;
                        //These 2 lines will not update the note without the PressSave();
                        //Guid noteGuid = (Guid)PXNoteAttribute.GetNoteID(Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current, null);
                        //PXNoteAttribute.UpdateNoteRecord(Base.Caches[typeof(APInvoice)], noteGuid, newNote);

                        PXNoteAttribute.SetNote(Base.Caches[typeof(APInvoice)], Base.Document.Current, newNote);  // Sets the note but, screen does not refresh.


                        //Base.Caches[typeof(APInvoice)].Update(Base.Document.Current); //Does not refresh Notes on screen.

                        //PXNoteAttribute.GetNoteID<APInvoice.noteID>(Base.Caches[typeof(APInvoice)], Base.Document.Current);  // Does not update the screen.

                        //Base.Caches[typeof(Note)].IsDirty = true;  /// No Effect.

                        //Base.Caches[typeof(Note)].Clear();  //this has no effect on refreshing the notes that are seen on the screen.
                        //Base.Caches[typeof(NoteDoc)].Clear();

                        //Base.Actions.PressSave();  // blanks out the header if the Bill has never been saved. Does not refresh note on screen.
                        //Base.Document.View.Clear();
                        //Base.Document.View.RequestRefresh();  // this wipes out the new note if adding a second PO.


                    }
                }


            }
        }

    }
MikeNIke
  • 221
  • 1
  • 10
  • Can you add the code you use to modify the note in your question? – Hugues Beauséjour Aug 29 '18 at 14:43
  • code added. sorry... – MikeNIke Aug 29 '18 at 15:06
  • Try to force cache invalidation, this SO answer might help you in doing so: https://stackoverflow.com/questions/46058668/how-to-automatically-create-note-record-in-acumatica – Hugues Beauséjour Aug 31 '18 at 15:51
  • Clearing the cache of Note/NoteDoc might help too since it won't be able to re-fetch the stale value from empty cache: Caches[typeof(Note)].Clear(); Caches[typeof(NoteDoc)].Clear(); – Hugues Beauséjour Aug 31 '18 at 16:00
  • Thanks for the suggestions. I gave them a shot plus a couple of other ideas but, I'm still not able to get the notes to update on the screen. I went back to using the SetNote() because of issues with the way I had it coded initially. I updated the code above to show what I've got at this point. – MikeNIke Sep 14 '18 at 16:14
  • But when you refresh the web page you do see them right? In that case perhaps calling the base graph Cancel action could refresh it too with the caveat that it invalidates the whole document. – Hugues Beauséjour Sep 14 '18 at 19:36
  • Yes, that's true - when I refresh the page, the notes are updated. Ok, I'll try Base.Actions.PressCancel and see what that does. – MikeNIke Sep 20 '18 at 13:18
  • Base.Actions.PressCancel() wreaks some havoc. If I use the "Add PO" button and try to add a PO that has two lines, the second line is skipped. Then, I get an error about a missing RefNbr field when I try to save the Bill. I added the PressCancel() right below the line that calls SetNote() on the RowInserted event handler. – MikeNIke Sep 20 '18 at 13:26
  • The idea is to call PressCancel() after calling PressSave() to save the document and immediately invalidate it so it refreshes. – Hugues Beauséjour Sep 20 '18 at 17:20

1 Answers1

0

Here's the fix for this that I deployed. I'm thinking that there is a better way to do this but, seems to be working ok for now. I added this:

    [PXOverride]
    public void Persist(Action persist)
    {
        persist();

        APInvoice invoice = (APInvoice)Base.CurrentDocument.SelectSingle();
        if (invoice.Status == "H")
            throw new PXRedirectRequiredException(Base, "Reloading Notes...");
    }

So, I overrode the Persist() in order to refresh the page but, I only do that if the Bill is still on Hold. This refreshes the Notes that are shown on the screen.

MikeNIke
  • 221
  • 1
  • 10