Skip to main content
Solved

Clearing Header Notes on Field Update


Forum|alt.badge.img

 

 

I need to clear the inserted header notes values when the additional information field below gets updated. I tried the code below, but the value remains. The header value sets to empty only when I refresh the page. What am I missing here?

 

                        var note = PXSelect<Note,
                        Where<Note.noteID, Equal<Required<Note.noteID>>>>

                        // Clear the header note field
                        note.NoteText = string.Empty;
                        Base.Caches<Note>().Update(note);

                        // Clear the caches to refresh the UI
                        Base.Caches<Note>().ClearQueryCache();
                        Base.Caches<Note>().Clear();
                        Base.Views.Caches.Remove(typeof(Note));
                        Base.Caches[typeof(Note)].Clear();
                        Base.Caches[typeof(Note)].ClearQueryCache();

 

Best answer by Naveen Boga

@rashmikamudalinayake10  As I explained above reg. GetNote and SetNote. 

I have used the same in your code and it will works as expected. Please check the below code and confirm.

 

public class BusinessAccountMaint_Extension : PXGraphExtension<PX.Objects.CR.BusinessAccountMaint>
{
    #region Event Handlers

    protected void BAccount_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
    {
        var row = (BAccount)e.Row;
        if (row != null)
        {
            var rowExt = PXCache<BAccount>.GetExtension<BAccountExt>(row);

                string noteText = PXNoteAttribute.GetNote(cache, row); 
                if (!string.IsNullOrEmpty(noteText))
                {
                    string userName = PXAccess.GetUserName();
                    string timeStamp = PXTimeZoneInfo.Now.ToString("yyyy.MM.dd HH:mm:ss");
                    string[] timeStampParts = timeStamp.Split(' ');
                    string datePart = timeStampParts[0];
                    string timePart = timeStampParts[1].Substring(0, 5);

                    string newNote = $"By: {userName} on: {datePart} at: {timePart}{Environment.NewLine}Note: \"{noteText}\"";

                    // Add the new note
                    if (!string.IsNullOrEmpty(rowExt.UsrNotes))
                    {
                        rowExt.UsrNotes = newNote + Environment.NewLine + rowExt.UsrNotes;
                    }
                    else
                    {
                        rowExt.UsrNotes = newNote;
                    }

                    // Persist to UsrNotes
                    cache.SetValueExt<BAccountExt.usrNotes>(row, rowExt.UsrNotes); 

                    PXNoteAttribute.SetNote(cache, row, string.Empty); 
            }
        }
    }
    #endregion
}

 

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

7 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3407 replies
  • July 4, 2024

Hi @rashmikamudalinayake10  To Set the value for the notes we should use the SetNote and to fetch the notes value and we should use the GetNote.

In your case, you can the set the empty value using SetNote. Below is the example in the link for your reference.

 

https://stackoverflow.com/questions/49141221/add-note-to-custom-data-record-in-code


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

@rashmikamudalinayake10,

Also, can share the event or method in which you are clearing the notes? I assume the view of the note section might not be refreshed like other views in the document.


Forum|alt.badge.img

@Vignesh Ponnusamy , @Naveen Boga 

below is my code. what I'm missing here.
 

using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.AR;
using PX.Objects.CR.Extensions.CRDuplicateEntities;
using PX.Objects.CR.Extensions.SideBySideComparison;
using PX.Objects.CR.Extensions.SideBySideComparison.Merge;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PX.Objects;
using PX.Objects.CR;
using PX.Common;

namespace PX.Objects.CR
{
	public class BusinessAccountMaint_Extension : PXGraphExtension<PX.Objects.CR.BusinessAccountMaint>
	{
        #region Event Handlers

        protected void BAccount_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            var row = (BAccount)e.Row;
            if (row != null)
            {
                var rowExt = PXCache<BAccount>.GetExtension<BAccountExt>(row);

                if (row.NoteID != null)
                {
                    var note = PXSelect<Note,
                        Where<Note.noteID, Equal<Required<Note.noteID>>>>
                        .Select(Base, row.NoteID).FirstOrDefault()?.GetItem<Note>();

                    if (note != null && !string.IsNullOrEmpty(note.NoteText))
                    {
                        string userName = PXAccess.GetUserName();
                        string timeStamp = PXTimeZoneInfo.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        string[] timeStampParts = timeStamp.Split(' ');
                        string datePart = timeStampParts[0];
                        string timePart = timeStampParts[1].Substring(0, 5);

                        string newNote = $"By: {userName} on: {datePart} at: {timePart}{Environment.NewLine}Note: \"{note.NoteText}\"";

                        // Add the new note
                        if (!string.IsNullOrEmpty(rowExt.UsrNotes))
                        {
                            rowExt.UsrNotes = newNote + Environment.NewLine + rowExt.UsrNotes;
                        }
                        else
                        {
                            rowExt.UsrNotes = newNote;
                        }

                        // Persist to UsrNotes
                        cache.SetValueExt<BAccountExt.usrNotes>(row, rowExt.UsrNotes);

                        // Clear the header note
                        note.NoteText = string.Empty;
                        Base.Caches<Note>().Update(note);

                        // Save changes to BAccount
                        cache.Update(row);
                        Base.Caches<Note>().Persist(PXDBOperation.Update);

                        // Clear the caches to refresh the UI
                        Base.Caches<Note>().ClearQueryCache();
                        Base.Caches<Note>().Clear();
                        Base.Views.Caches.Remove(typeof(Note));
                        Base.Caches[typeof(Note)].Clear();
                        Base.Caches[typeof(Note)].ClearQueryCache();

                    }
                }
            }
        }
        #endregion
    }
}

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3407 replies
  • Answer
  • July 5, 2024

@rashmikamudalinayake10  As I explained above reg. GetNote and SetNote. 

I have used the same in your code and it will works as expected. Please check the below code and confirm.

 

public class BusinessAccountMaint_Extension : PXGraphExtension<PX.Objects.CR.BusinessAccountMaint>
{
    #region Event Handlers

    protected void BAccount_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
    {
        var row = (BAccount)e.Row;
        if (row != null)
        {
            var rowExt = PXCache<BAccount>.GetExtension<BAccountExt>(row);

                string noteText = PXNoteAttribute.GetNote(cache, row); 
                if (!string.IsNullOrEmpty(noteText))
                {
                    string userName = PXAccess.GetUserName();
                    string timeStamp = PXTimeZoneInfo.Now.ToString("yyyy.MM.dd HH:mm:ss");
                    string[] timeStampParts = timeStamp.Split(' ');
                    string datePart = timeStampParts[0];
                    string timePart = timeStampParts[1].Substring(0, 5);

                    string newNote = $"By: {userName} on: {datePart} at: {timePart}{Environment.NewLine}Note: \"{noteText}\"";

                    // Add the new note
                    if (!string.IsNullOrEmpty(rowExt.UsrNotes))
                    {
                        rowExt.UsrNotes = newNote + Environment.NewLine + rowExt.UsrNotes;
                    }
                    else
                    {
                        rowExt.UsrNotes = newNote;
                    }

                    // Persist to UsrNotes
                    cache.SetValueExt<BAccountExt.usrNotes>(row, rowExt.UsrNotes); 

                    PXNoteAttribute.SetNote(cache, row, string.Empty); 
            }
        }
    }
    #endregion
}

 


Forum|alt.badge.img

Hi @Naveen Boga 

I tried it in the local instance, but the issue remains the same. However, when I debug, the record is cleared from PXNoteAttribute.SetNote(cache, row, string.Empty);. I need to test it on the server; sometimes it might work.


By the way, thanks @Naveen Boga and @Vignesh Ponnusamy for helping. I’ll update the thread once I test it on the server.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3407 replies
  • July 8, 2024

@rashmikamudalinayake10  I verified the above code and it is working as expected. Please double check from your end / verify it in the different instance.


Forum|alt.badge.img

Yes it was an instance issue.

Thanks @Naveen Boga , @Vignesh Ponnusamy

 


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