Page 3 of 3

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

Posted: Thu Dec 12, 2019 11:14 am
by BobRichards
If you open the order via API, does the "TrustAccountId" tag exist in the Order object's tag collection? Is the guid value a valid trust account?

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

Posted: Thu Dec 12, 2019 12:37 pm
by dlerickson
In both cases, the answer is "yes." What I'm doing is providing a dropdown list to a user with possible trust accounts, the data for which is pulled as such:

Code: Select all

var accountsManager = SelectServer.GetService<IAccountsManager>();
var trustAccounts = accountsManager.TrustAccounts
	.Where(x => x.Enabled)
	.ToList();
The user selects one of these, and the code to set the order to that Trust Account is as such:

Code: Select all

order.SetTag("TrustAccountId", TrustAccount.ID.ToString());	// TrustAccount is the user-select Trust Account object here
I'm also calling ApplyChanges immediately after this, in an outer scope.

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

Posted: Wed Apr 29, 2020 11:43 am
by uwdoug79
So we only have 1 trust account so I wanted to set it directly but this does not appear to be working.

order.SetTag("TrustAccountId", "WICTUSB7743");

should this work ??

Doug

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

Posted: Wed Apr 29, 2020 11:52 am
by BobRichards
A TrustAccount.ID is a guid value that we store as a string. You will have to do a lookup of the trust account name to get the guid.

Code: Select all

IAccountsManager accountsManager = SelectServer.GetService<IAccountsManager>();
ITrustAccountInfo trustAccountInfo = accountsManager.TrustAccounts
    .Where(x => x.Code == "WICTUSB7743")
    .FirstOrDefault();

order.SetTag("TrustAccountId", trustAccountInfo.ID.ToString());