Skip to main content

Notifications

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;

  • Verified answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 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.

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

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

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: 'Wrong parameters specified' at renamePrimaryKey()

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

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 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.

  • Harshal Jain Profile Picture
    Harshal Jain 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));

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,853 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
    Harshal Jain 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;

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 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

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans