Notifications
Announcements
No record found.
Hi ,
While running the following piece of code, I am getting the error of wrong parameter specified at "vendTable.renamePrimaryKey()". Tried to debug too but did't get the solution.
ttsbegin; while select crosscompany AccountNum,count(RecId) from vendTable order by vendTable.AccountNum asc group by vendTable.AccountNum where vendTable.AccountNum == 'V-001165' { if(vendTable.RecId > 1 ) { vendTable.AccountNum = sequence.num(); vendTable.renamePrimaryKey(); } } ttscommit;
Hi Harshal, Issue seems to be in line# 12, you are not calling to vendor account number sequence. is this the complete code?
community.dynamics.com/.../how-can-i-update-the-vendor-id-with-new-number-seq-by-sql-via-code
Hi Mohit,
I have used it. Let me put the entire code -
VendTable vendTable; NumberSeq sequence; sequence = NumberSeq::newGetNum( VendParameters::numRefVendAccount()); ttsbegin; while select crosscompany AccountNum,count(RecId) from vendTable order by vendTable.AccountNum asc group by vendTable.AccountNum where vendTable.AccountNum == 'V-001165' { if(vendTable.RecId > 1 ) { vendTable.AccountNum = sequence.num(); vendTable.renamePrimaryKey(); } } ttscommit;
The problem may be in the fact that you're calling renamePrimaryKey() on a table buffer that doesn't have a valid value in RecId field. Try loading the whole buffer before renaming.
Also, you likely should run it in the context of the target company.
For example:
CustAccount accountNum = 'V-001165'; ttsbegin; VendTable vendCount; select crosscompany count(RecId) from vendCount where vendCount.AccountNum == accountNum if (vendCount.RecId <= 1) { return; } NumberSeq sequence = NumberSeq::newGetNum(VendParameters::numRefVendAccount()); VendTable vendCompany; while select crosscompany DataAreaId from vendCompany where vendCompany.AccountNum == accountNum { changeCompany(vendCompany.DataAreaId) { VendTable vendForRename = VendTable::find(accountNum); vendForRename.AccountNum = sequence.num(); vendForRename.renamePrimaryKey(); } } ttscommit;
Hi Martin,
Yes, this was the issue. Thanks for suggesting the solution. But if I run the following code it should return 3 as we have 3 records in ax but it return only 1. Please suggest where I am going wrong. Thanks in advance
int counter = 0; while select crosscompany AccountNum, count(RecId) from vendCount group by vendCount.AccountNum where vendCount.AccountNum == 'V-001165' { if (vendCount.RecId > 1) { counter ; } } info(int2str(counter));
I tried replicating your code and got same error and reason for that error is table buffer is missing. If you put breakpoint on add method in info class and run this code, it will point you to logic where its failing on condition table is null. So as martin suggested, you need to initialize vendTable buffer again.
It will not return 3 records due to group by condition.
Even the order by and group by condition doesn't return the result as 3.
order by is just for sorting, group by will combine those 3 records into 1 because all those records have same accountNum.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 646 Most Valuable Professional
André Arnaud de Cal... 529 Super User 2025 Season 2
Sohaib Cheema 285 User Group Leader