能否通过DynamicsGPClient获取应付交易的下一个凭证号?
I’ve run into this exact issue before—getting old cached data instead of the latest next voucher number for Accounts Payable transactions using DynamicsGPClient. Here are the most common fixes and checks to try:
Clear or refresh client-side cache
DynamicsGPClient often caches sequence and metadata info to boost performance, especially if your client instance runs long-term. Try restarting your client application first, or explicitly call the cache refresh method if your version supports it. For example:dynamicsGP.RefreshCache(CacheRefreshType.All);This forces the client to pull fresh data straight from the GP server instead of relying on local cached values.
Verify you’re targeting the correct sequence
AP voucher numbers are tied to a specific sequence configuration in GP. Make sure you’re using the rightSequenceKeywhen fetching the next number—double-check the sequence ID matches what’s set up in your GP environment (you can find this in GP under Tools > Setup > Company > Sequences). A properly structured call might look like this:var apSequenceKey = new SequenceKey { Series = Series.AccountsPayable, SequenceId = "AP_VOUCHER" // Match your GP sequence ID here }; var nextVoucherNumber = dynamicsGP.GetNextSequenceNumber(apSequenceKey);Check transaction isolation levels
If your query runs inside an uncommitted transaction, it might not pick up the latest sequence updates. Ensure your API calls execute in a context withReadCommittedisolation level (the default for most GP operations), or run the sequence lookup outside any open transactions entirely.Validate server-side sequence state
Log into the Dynamics GP desktop client manually and check what the next expected AP voucher number is. If the desktop client shows the correct latest number but your API returns stale data, this confirms the issue is client-side cache rather than a server-side problem.Use the official
GetNextSequenceNumbermethod instead of direct table queries
Avoid querying tables likeSY00100directly for sequence data. The officialGetNextSequenceNumbermethod handles server-side locks and cache invalidation properly, so you’ll get the actual next available number instead of a stale cached value.
内容的提问来源于stack exchange,提问作者Ash King

