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;
order by is just for sorting, group by will combine those 3 records into 1 because all those records have same accountNum.
Even the order by and group by condition doesn't return the result as 3.
It will not return 3 records due to group by condition.
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.
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));
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 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;
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
André Arnaud de Cal...
291,996
Super User 2025 Season 1
Martin Dráb
230,853
Most Valuable Professional
nmaenpaa
101,156