0
votes

I was searching for a solution to add a note to a database row I am creating in a custom table. I found the solution below from Ruslan for accessing the noteid, but I don't understand how this would be used to add a note to the row. I have all the code to create the row, I just need the attributes or function call to actually attach the text of the note to the row.

==================================================================

To have Note record automatically created when a new parent record gets saved, one should invoke the static PXNoteAttribute.GetNoteID(PXCache cache, object data) method when the parent record is inserted in the cache.

For example, to have Note record automatically created when a new Stock Item gets saved, you should subscribe to RowInserted handler for the InventoryItem DAC and call PXNoteAttribute.GetNoteID(...):

public class InventoryItemMaintExt : PXGraphExtension<InventoryItemMaint>
{
    public void InventoryItem_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
    {
        var noteCache = Base.Caches[typeof(Note)];
        var oldDirty = noteCache.IsDirty;
        PXNoteAttribute.GetNoteID<InventoryItem.noteID>(sender, e.Row);
        noteCache.IsDirty = oldDirty;
    }
}

The code snippet above can be incorporated into almost any custom BLC with a couple simple changes to replace InventoryItem with a custom DAC.


After implementing Gabriel's suggestions:

I do not seem to get any note in the database. The code compiles and runs fine, but the notes are not generated as far as I can tell. The note id is set in my table, but no data appears in the note table. Please take a look at my code and let me know what needs to change. Also, how do I get the note column into a grid, or does it automatically become available when it is done correctly?

Database field definition:

[NoteID] [uniqueidentifier] NULL

DAC field:

    #region NoteID
    public abstract class noteID : PX.Data.IBqlField
    {
    }
    protected Guid? _NoteID;
    [PXNote()]
    public virtual Guid? NoteID
    {
        get
        {
            return this._NoteID;
        }
        set
        {
            this._NoteID = value;
        }
    }
    #endregion

Code to create record:

    private static bool acumaticaException(Exception e, EDImportExceptionMaint excpMaint, LingoRet850 res850)
    {
        excpMaint.Clear();
        var except = new EDImportExcept();
        except.ExceptReason = "U";
        except.Active = true;

        <...field assignments...>

        except.OrderNbr = "";
        PXNoteAttribute.SetNote(excpMaint.Exception.Cache, excpMaint.Exception.Current, 
            ((PX.Data.PXOuterException)e).InnerMessages[0] + "-" + e.Message);
        excpMaint.Exception.Insert(except);
        excpMaint.Actions.PressSave();
        return true;
  }
1
i believe that just generates the noteid record - not note text if that is what you are looking for?Brendan
Yes, I am looking for the code to establish the note record/text and any other attributes so as to have the note indication on the grid for my screen and make it able to be displayed in a popup by clicking on it. Just guessing, but to I need to use the code above to generate the note record and then update it? I thought there would be specific functions or attributes to set the text.Jerry Welliver
The problem is that you are setting the Note before actually inserting the except record into the cache. Insert it and then set the note and it shall work. I also suspect it will work if you just replace excpMaint.Exception.Current with except, but still think it's better to insert the record first (it doesn't hit the DB until you do PressSave())Gabriel
Merci Beaucoup!! Makes total sense but just one of those little concepts you can miss. Just one quick question. Is it best to set the note before the PressSave or after?Jerry Welliver
Also, I use a dynamic DAC in a graph to display data from multiple tables in a processing grid. Do I have to get the note from the custom table and then set it to the dynamic DAC so it will show? Is there anything special to get the note into the grid?Jerry Welliver

1 Answers

3
votes

To set the note of a record, use the SetNote()static function of PXNoteAttribute

PXNoteAttribute.SetNote(Base.Item.Cache, Base.Item.Current, "Hello, World!");

Calling SetNote will also take care of adding the Note record if it doesn't exist, so you don't have to call GetNoteID before setting the note value as in your question.

P.S. There is also a GetNote function which allows you to retrieve the current value of the note:

string note = PXNoteAttribute.GetNote(Base.Item.Cache, Base.Item.Current);