Setting the Trust Account for an order via the API
Posted: Tue Feb 07, 2012 11:53 am
I might just be missing it, but where do you set the trust account for an order during creation via the API?
Thanks,
Michael
Thanks,
Michael
Free support for custom code within SoftPro's products, monitored by SoftPro employees with a 24-48 hr expected turn time on business days.
https://devforum.softprocorp.com/
Code: Select all
// sample to illustrate the creation of an order (blank) with a trust account
IAccountsManager am = _sps.GetService<IAccountsManager>();
ITrustAccountInfo tacInfo = am.TrustAccounts
.Where(ta => ta.Code == "TACode")
.SingleOrDefault();
if (tacInfo != null)
{
OrderCreationSpec spec = new OrderCreationSpec();
spec.BaseNumber = "TestOrder1";
spec.Settings.Add("TrustAccountId", tacInfo.ID.ToString());
IOrderStore os = _sps.GetService<IOrderStore>();
using (IOrder order = os.NewOrder(spec))
{
// order save
os.ApplyChanges(order);
}
}
Code: Select all
public void AddTrustAccount(string orderNumber)
{
var configuration = GetConfiguration();
using (var selectServer = GetSelectServer(configuration))
{
var orderStore = selectServer.GetService<IOrderStore>();
var orderInfo = orderStore.Orders.FirstOrDefault(x => x.Number == orderNumber);
var order = orderStore.OpenOrder(orderInfo, false);
var accountsManager = selectServer.GetService<IAccountsManager>();
var trustAccountInfo = accountsManager.TrustAccounts.FirstOrDefault();
order.SetTag("TrustAccountId", trustAccountInfo.ID.ToString());
}
}