Page 2 of 3

Re: Setting the Trust Account for an order via the API

Posted: Thu Feb 12, 2015 3:28 pm
by John Morris
You need to save the order after adding the tag.

Re: Setting the Trust Account for an order via the API

Posted: Thu Feb 12, 2015 3:32 pm
by sindrapal
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);
}
}
}

Re: Setting the Trust Account for an order via the API

Posted: Thu Feb 12, 2015 5:08 pm
by mrisen
Ah, that was it. Silly mistake. Thank you!

Re: Setting the Trust Account for an order via the API

Posted: Tue Jul 28, 2015 5:08 pm
by tmeisinger
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.

Re: Setting the Trust Account for an order via the API

Posted: Tue Jul 28, 2015 5:48 pm
by tmeisinger
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

Posted: Tue Jul 28, 2015 6:50 pm
by mrisen
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.

Re: Setting the Trust Account for an order via the API

Posted: Wed Jul 29, 2015 8:16 am
by tmeisinger
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

Posted: Wed Jul 29, 2015 9:44 am
by sindrapal
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();

Re: Setting the Trust Account for an order via the API

Posted: Wed Jul 29, 2015 11:53 am
by tmeisinger
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.

Re: Setting the Trust Account for an order via the API

Posted: Wed Dec 11, 2019 7:31 pm
by dlerickson
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?