UpdateRecordSet will use dynamic fields?

Hi all,

Table details
Table have two fields (Num, val)

Form details
I have two buttons in the form, if we click on the first button then it will update some values to the ‘Num’ field and if we click on the second button then it will update values to the ‘Val’ field.

The following codes am using in the button clicked method,

update_recordset myTable
setting
Num = ‘Values’
where myTable.RecId == ‘5673412488’

update_recordset myTable
setting
Val = ‘Increase’
where myTable.RecId == ‘5673412488’

So is there any way to reduce these codes ?

Like create a common method and pass only the field (Num, val) ?

type or paste code here

Is update_recordset worth is if you update a single record?

The usual approach is something like this:

MyTable myTable = MyTable::find(5673412488);

if (...)
{
    myTable.Num = 'Values';
}
else
{
    myTable.Val = 'Increase';
}

myTable.update();

Thanks for your input martin

It will update a multiple records, so this wnot be work my scenario.

Any other suggestions pls

Aha, so your sample code does not demonstrate your scenario.

In that case, use Query::update_recordset() method. Here is an example from WHSPrintLabels class:

Query                   waveLabelQuery = new Query();
QueryBuildDataSource    qbdsWaveLabel = waveLabelQuery.addDataSource(tableNum(WHSWaveLabel));

qbdsWaveLabel.addRange(fieldNum(WHSWaveLabel, WaveLabelId)).value(rangeValue);

Map fieldSetMap = new Map(Types::String, Types::String);

fieldSetMap.insert(fieldStr(WHSWaveLabel, Printed), any2Str(NoYes::Yes));
fieldSetMap.insert(fieldStr(WHSWaveLabel, PrintedDateTime), DateTimeUtil::toStr(printedDateTime));
fieldSetMap.insert(fieldStr(WHSWaveLabel, PrintedBy), printedBy);

Query::update_recordset(fieldSetMap, waveLabelQuery);

Tried based on your input but getting an error
I hardcoded the value also but getting an error

type or paste code here
ttsbegin;

Query                   waveLabelQuery = new Query();
QueryBuildDataSource    qbdsWaveLabel = waveLabelQuery.addDataSource(tableNum(DFMSearchRecords));

qbdsWaveLabel.addRange(fieldNum(DFMSearchRecords, RefTableId)).value(queryValue(TmpTableName.RefTableId));  
//qbdsWaveLabel.addRange(fieldNum(DFMSearchRecords, RefTableId)).value('66171');

Map fieldSetMap = new Map(Types::String, Types::String);

fieldSetMap.insert(fieldStr(DFMSearchRecords, Alpha2), strMin());

Query::update_recordset(fieldSetMap, waveLabelQuery, true);

ttscommit;

getting an error ‘Query extended range failure: Syntax error near 2.’

any suggestion pls

What is the stack trace of the exception?

Could you try it on a standard table, please? It’ll be easier for others to help you than when you’re using a table and fields that we can’t review and we can’t run your code.

I tried with salesLine table, same error in the range

type or paste code here

ttsbegin;

Query waveLabelQuery = new Query();
QueryBuildDataSource qbdsWaveLabel = waveLabelQuery.addDataSource(tableNum(SalesLine));
str projId = ‘DEMF-000801’;
SalesLine salesLine;

salesLine = SalesLine::find(‘002411’);

qbdsWaveLabel.addRange(fieldNum(SalesLine, RecId)).value(queryValue(salesLine.RecId));

Map fieldSetMap = new Map(Types::String, Types::String);

fieldSetMap.insert(fieldStr(SalesLine, ProjId), projId);

Query::update_recordset(fieldSetMap, waveLabelQuery);

Info (“done”);

ttscommit;

getting an error

I’ve been to able to reproduce the problem; I don’t know how to convince the function to interpret it as a value and not a field name.

I suggest logging a support request with Microsoft, because it’s kernel code and our options to analyze it are limited.