Setting the Trust Account for an order via the API
-
- Posts: 411
- Joined: Thu Sep 11, 2008 11:35 am
- Location: Raleigh, NC, USA
- Contact:
Re: Setting the Trust Account for an order via the API
You need to save the order after adding the tag.
John Morris
Sr. Software Architect
SoftPro
Sr. Software Architect
SoftPro
Re: Setting the Trust Account for an order via the API
I don't see where you save the order after setting that tag. Can you please try this?
public void AddTrustAccount(string orderNumber)
{
var configuration = GetConfiguration();
using (var selectServer = GetSelectServer(configuration))
{
IOrderStore orderStore = selectServer.GetService<IOrderStore>();
var orderInfo = orderStore.Orders.FirstOrDefault(x => x.Number == orderNumber);
IOrder order = null;
using (order = orderStore.OpenOrder(orderInfo, false))
{
var accountsManager = selectServer.GetService<IAccountsManager>();
var trustAccountInfo = accountsManager.TrustAccounts.FirstOrDefault();
order.SetTag("TrustAccountId", trustAccountInfo.ID.ToString());
orderStore.ApplyChanges(order);
}
}
}
public void AddTrustAccount(string orderNumber)
{
var configuration = GetConfiguration();
using (var selectServer = GetSelectServer(configuration))
{
IOrderStore orderStore = selectServer.GetService<IOrderStore>();
var orderInfo = orderStore.Orders.FirstOrDefault(x => x.Number == orderNumber);
IOrder order = null;
using (order = orderStore.OpenOrder(orderInfo, false))
{
var accountsManager = selectServer.GetService<IAccountsManager>();
var trustAccountInfo = accountsManager.TrustAccounts.FirstOrDefault();
order.SetTag("TrustAccountId", trustAccountInfo.ID.ToString());
orderStore.ApplyChanges(order);
}
}
}
Re: Setting the Trust Account for an order via the API
Ah, that was it. Silly mistake. Thank you!
-
- Posts: 75
- Joined: Fri Apr 24, 2015 10:33 am
Re: Setting the Trust Account for an order via the API
I just experienced the same problem, it looks like I'm setting the Trust Account at Order Creation, but when going into the order in ProForm and clicking on the Register, it asks for a Trust Account. Any thoughts? Also, I'm doing this under a test profile with a test user that can only see Trust Accounts under the test profile when I log in. However, when I use the API with the same test user to search for a Trust Account, the linq query can see all of the Trust Accounts. Any feedback on this would be appreciated as well.
-
- Posts: 75
- Joined: Fri Apr 24, 2015 10:33 am
Re: Setting the Trust Account for an order via the API
I should have clarified, I'm setting the Trust Account with the Order Creation Spec before creating the Order and then I set a number of Order values before Applying Changes. The Order creates using the Spec's Template and Settlement Type, and all of the Order values, but the Trust Account isn't selected when I go to the Register.
Re: Setting the Trust Account for an order via the API
I'm just guessing here, but I suspect you can't set the trust account until after the order is created. I think you should try creating an order, saving it, then set the trust account, then save it again.
-
- Posts: 75
- Joined: Fri Apr 24, 2015 10:33 am
Re: Setting the Trust Account for an order via the API
You are correct. If I create the Order, set all the values (except Trust Account ID), apply Changes, close the Order, then re-Open the Order, set the Trust Account ID, apply Changes and close the Order, it will work. This sure adds overhead to my Order creation process, any other ideas???
Re: Setting the Trust Account for an order via the API
Can you please paste your code? You should be able to set the trust account while creating the order (before the first save). This is exactly what Select does if you pick a trust account on the new order dialog. Also, please verify that your active profile has access to the trust account. Even if you did set the trust account while creating the order, you will get the Select Trust Account dialog prompting you to pick a trust account if your active profile doesn't have access to the Ledger's existing trust account.
// Verify if your active profile has access to the trust account
IProfile activeProfile = _sps.GetService<IProfileManager>().ActiveProfile;
IAccountsManager accountsManager = _sps.GetService<IAccountsManager>();
bool hasAccess = accountsManager
.TrustAccounts
.Search(new ClosestAncestorProfileSearch(activeProfile))
.Where(t => t.ID == ledgerInfo.TrustAccount.ID)
.ToList()
.Any();
// Verify if your active profile has access to the trust account
IProfile activeProfile = _sps.GetService<IProfileManager>().ActiveProfile;
IAccountsManager accountsManager = _sps.GetService<IAccountsManager>();
bool hasAccess = accountsManager
.TrustAccounts
.Search(new ClosestAncestorProfileSearch(activeProfile))
.Where(t => t.ID == ledgerInfo.TrustAccount.ID)
.ToList()
.Any();
-
- Posts: 75
- Joined: Fri Apr 24, 2015 10:33 am
Re: Setting the Trust Account for an order via the API
After further Testing, I found that TrustAccountId (small d) works much better than TrustAccountID. Didn't realize the spec.Settings are case sensitive. Thanks for your reply.
-
- Posts: 80
- Joined: Tue Jan 21, 2014 11:35 am
- Location: Austin, TX
Re: Setting the Trust Account for an order via the API
Hi, I found that snippet for setting the Trust Account in the post above in this thread. I'm using it in my code, but when the code gets run, the Trust Account does not get set, and there are no errors being thrown, or any other messaging that I can see. What are the blocking conditions which would prevent setting the Trust Account?