Discussions concerning general integration topics.
Moderator: Phil Barton
- Posts: 17
- Joined: Tue Mar 09, 2010 2:27 pm
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!
- Posts: 1116
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
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();
Bob Richards, Senior Software Developer, SoftPro