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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Query::update_recordset() method not working

(2) ShareShare
ReportReport
Posted on by 104
I try to use the method for optimization purposes in order to avoid row by row update:
 
Query query = new Query();
QueryBuildDataSource qbds = query.addDataSource(tableNum(CustVendPDCRegister));
Map fieldSetMap = new Map(Types::String, Types::String);
     
qbds.addRange(fieldNum(CustVendPDCRegister, RecId)).value(con2str(conRecords));
fieldSetMap.insert(fieldStr(CustVendPDCRegister, Comments), 'hello');
 
try
{
    ttsbegin;
    int64 recordsUpdated = Query::update_recordset(fieldSetMap, query, true, true, true);
    ttscommit;
    info(int642Str(recordsUpdated));
}
catch
{
    Global::error('error');
}
 
Firstly, I get the error: 'Query extended range failure: CustVendPDCRegister_1.hello is not a valid datasource.field pair near pos 7.'
Besides that main part of the problem, when I put a number string(e.g. '5') in value parameter, no error occurs so I can see that it enters the override of update() for every record, despite the fact that I have put true in parameters skipDataMethods, skipEvents and skipDatabaseLog.
I have the same question (0)
  • Raj Borad Profile Picture
    1,578 on at
    Error in first line describes that the hello is not a valid field in the table.
    Maybe there is some missing of changes required in the code in line number 7 (while map.insert(()).
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,811 Super User 2026 Season 1 on at
    Hi @ â€‹â€‹â€‹â€‹â€‹â€‹â€‹,
     
    Try this :
    fieldSetMap.insert(fieldStr(CustVendPDCRegister, Comments), any2Str('hello'));
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    Waed Ayyad Profile Picture
    9,212 Super User 2026 Season 2 on at
    Hi,
     
    Can you print the Query on an info message and share it here? Also, when you debug the code where your code was failed?  regarding the range value do you means when you put number it is working? and the data is saved?
     
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Vasileios Papoglou Profile Picture
    104 on at
    Hi Waed,
     
    if I select 3 records for example, the query is: "SELECT * FROM CustVendPDCRegister(CustVendPDCRegister_1) WHERE ((RecId = 65371... OR RecId = 65371... OR RecId = 65371...))" which is correct.
     
    The code fails exactly on the update_recordset by raising the exception mentioned in the question.
     
    No, when I put the number, data is not saved either, it just doesn't raise an exception. I mention it just in case it helps someone understand better what is wrong.
  • Suggested answer
    Layan Jwei Profile Picture
    8,282 Super User 2026 Season 2 on at
    Hi,

    Can you show us full code please. I wonder why you are using con2Str in the first place, so i would like to see how conRecords is being filled please. Are u not getting those RecIds from a caller?

    So if for example you are using sysOperationFramwork where u are selecting records, then i would assume in the controller class, you have a method like this:
         FormDataSource       dataSource        = FormDataUtil::getFormDataSource(args.record());
         Contract             contract          = this.getDataContractObject();
         MultiSelectionHelper selectionHelper   = MultiSelectionHelper::construct();
    
         TableX                tableX;
         QueryBuildDataSource  qbds;
         QuerybuildRange       qbr;
    
         selectionHelper.parmDataSource(dataSource);
    
         tableX = selectionHelper.getFirst();
    
         Query query = contract.getQuery();
    
         while (tableX)
         {
             qbds = query.dataSourceTable(tableNum(TableX));
             qbr  = qbds.addRange(fieldNum(TableX, RecId));
             qbr.value(queryvalue(TableX.RecId));
                     
             tableX= selectionHelper.getNext();
         }
    
         contract.setQuery(query);

    Then in the service class, you can have code like this:
    public class Service extends SysOperationServiceBase
    {
    
        public void process(Contract _contract)
        {
            
            TableX                 tableX;
            System.Exception       ex;
            Map                    updateFieldMapping   = new Map(Types::String, Types::String);
            Query                  query                = _contract.getQuery();
    
            
            updateFieldMapping.insert(fieldStr(TableX, Comment), 'Hello');
    
            try
            {
                ttsbegin;
                Query::update_recordset(updateFieldMapping, query); // you can assign true to other variables in this method
                ttscommit;
            }
            catch(ex)
            {
                throw error(ex.Message);
            }
        }
    
    }

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Vasileios Papoglou Profile Picture
    104 on at
    Hello Layan,
     
    there is not something fancy in the previous part of the code, I just receive a FormDataSource(CustVendPDCRegister) and put all the marked records in a container in order to use their RecIds as range for the update. My code is like this:
    public void updateComments(FormDataSource ds)
    {
        CustVendPDCRegister pdcRegister;
        Container conRecords;
        pdcRegister = ds.gerFirst(1);
        while (pdcRegister)
        {
            conRecords += int642Str(pdcRegister.RecId);
            pdcRegister = ds.getNext();
        }
        //rest of the code...
    }
     
  • Martin Dráb Profile Picture
    240,281 Most Valuable Professional on at
    What's the benefit of converting RecIds to strings? I expect your range value will be wrong because of that. Also, it's better to adding a single range for each value, rather than concatenating them to a string.
     
    Start with a single value:
    CustVendPDCRegister pdcRegister = _registerDs.cursor();
    qbds.addRange(fieldNum(CustVendPDCRegister, RecId)).value(queryValue(pdcRegister.RecId));
    If it doesn't work, there no point in bothering with the while loop. You'll save time and get a simpler test case.
     
    If it works for a single record, you can add the additional feature. Getting more records (by executing the query, using MultiSelectingHelper or so) and add a range for each applicable record. If you want all records of the data source, you don't need to create a new query, but it already exists.
  • Vasileios Papoglou Profile Picture
    104 on at
    Hi Martin,
     
    in a comment below I wrote the query that is constructed and it seems that the range is fine. However, I followed your advice for making things simpler but it doesn't work either for the ds.cursor() record. In fact, even if I put a hard-coded RecId in queryValue it continues to raise the error.
    It seems like something is wrong with the function. It sees the Map Value(e.g. 'hello') as Map Key(field name) and the parameters for skipping Data Methods and Events are not working.
  • Martin Dráb Profile Picture
    240,281 Most Valuable Professional on at
    Good, we at least simplified the test case and ignore all the code dealing with containers of RecIDs etc, because we've proven that it's not relevant to the problem.
     
    Honestly, I've never understood how update_recordset() is supposed to work in this case. I noticed before that it interprets a string value as a field name. The only workaround I can think of is having the value in a field returned by the query (likely in a temporary table).
  • Vasileios Papoglou Profile Picture
    104 on at
    I have already a workaround ready by using the classic way of while and doUpdate but I try to optimize it with an update recordset. The weird part is that I have found this update_recordset method used by other classes like CustBalanceList, VendBalanceList and ACOVoidAbsorbedProdCost_BR the same way as I did.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 265 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 261 Super User 2026 Season 2

#3
Subra Profile Picture

Subra 229 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans