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, ...
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)
  • Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    Query::update_recordset() method not working
    Sure, not using update_recordset() is an option too, but I meant a solution for update_recordset().
     
    CustBalanceList and VendBalanceList use field names, not string values. ACOVoidAbsorbedProdCost_BR is about an enum, not a string, which makes a difference in my experience.
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Query::update_recordset() method not working
    Few days back I also used this standard function and ended up with a normal while select for update. This gave me the same error which Vasileios also getting. I tried  first with con2str then a single value and finally a hard-coded string. Seems there is some issue with this method itself.
  • Vasileios Papoglou Profile Picture
    104 on at
    Query::update_recordset() method not working
    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.
  • Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    Query::update_recordset() method not working
    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
    Query::update_recordset() method not working
    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
    235,979 Most Valuable Professional on at
    Query::update_recordset() method not working
    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
    Query::update_recordset() method not working
    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...
    }
     
  • Suggested answer
    Layan Jwei Profile Picture
    7,997 Super User 2025 Season 2 on at
    Query::update_recordset() method not working
    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
    Query::update_recordset() method not working
    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
    Waed Ayyad Profile Picture
    8,881 Super User 2025 Season 2 on at
    Query::update_recordset() method not working
    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
     

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 882 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 518

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans