web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

'Wrong parameters specified' at renamePrimaryKey()

(0) ShareShare
ReportReport
Posted on by 162

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;

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: Getting error - 'Wrong parameters specified'

    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

  • Harshal Jain Profile Picture
    162 on at
    RE: Getting error - 'Wrong parameters specified'

    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;

  • Verified answer
    Martin Dráb Profile Picture
    237,662 Most Valuable Professional on at
    RE: Getting error - 'Wrong parameters specified'

    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;

  • Harshal Jain Profile Picture
    162 on at
    RE: 'Wrong parameters specified' at renamePrimaryKey()

    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));

  • Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: 'Wrong parameters specified' at renamePrimaryKey()

    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.

  • Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: 'Wrong parameters specified' at renamePrimaryKey()

    It will not return 3 records due to group by condition.

  • Harshal Jain Profile Picture
    162 on at
    RE: 'Wrong parameters specified' at renamePrimaryKey()

    Even the order by and group by condition doesn't return the result as 3.

  • Verified answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: 'Wrong parameters specified' at renamePrimaryKey()

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 724 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 619 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 400 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans