Page 1 of 1

Add Ledger Note

Posted: Thu Feb 28, 2019 12:18 pm
by mmregan
I am trying to use the API to add a Ledger Note. Using the SDK reference, I have attempted the following:

Code: Select all

private void CreateLedgerNote()
       {
           dynamic dynamicOrder = this.workingMasterOrder as dynamic;
           SelectServer sps = ServiceContext.GetService<SelectServer>();
           ILedgersManager lm = sps.GetService<ILedgersManager>();
           ILedgerInfo masterOrderLedgerInfo = lm.GetLedgerForOrder(this.workingMasterOrder.Identifier.Guid);
           ILedger masterLedger = lm.GetLedger(masterOrderLedgerInfo);
           IOrderLedger masterOrderLedger = masterLedger as IOrderLedger;
           INote newNote = masterOrderLedger.NewNote(); // have also tried calling this on ILedger masterLedger
           newNote.Content = "my ledger note";
           masterOrderLedger.Notes.Add(newNote); // does not seem to actually add the note per looking in debugger
           lm.ApplyChanges(masterOrderLedger); // this may not be appropriate, maybe just an order save is the answer?
       }
But as you can see from the comments, the note does not seem to actually get added to the ledger. Please advise!
Thanks.

Re: Add Ledger Note

Posted: Thu Feb 28, 2019 4:12 pm
by BobRichards
It works for me. (I modified your code slightly - just to make it more readable to others).

For me, when the code runs, the note is added to the order ledger. If I am viewing the order ledger in Select then run the application, the GUI will not be updated automatically. You can keep Select open, but you must close then reload the ledger to see the additional note.

Code: Select all

public CreateLedgerNote(SelectServer ss)
{
    Guid orderID = ss.GetService<IOrderStore>().Orders.Where(t => t.Number == "XAT19000010").First().Identifier.Guid;

    ILedgersManager ledMgr = ss.GetService<ILedgersManager>();
    ILedgerInfo ledInfo = ledMgr.GetLedgerForOrder(orderID);
    IOrderLedger ledger = (IOrderLedger)ledMgr.GetLedger(ledInfo);
    
    INote note = ledger.NewNote();
    note.Content = "Hi! I'm a new note: " + DateTime.Now.ToShortTimeString();

    ledger.Notes.Add(note);
    ledMgr.ApplyChanges(ledger);
}