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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

unable to update a record fetched via QueryRun

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

i have a problem to update a record that i fetched via QueryRun. I call 'selectForUpdate(true)' on the table buffer before updating but it doesn't seem to have an effect.

The error is classical:

Cannot edit a record in Configuration element (FWPPBATreeNode).
The operation cannot be completed, since the record was not selected for update. Remember TTSBEGIN/TTSCOMMIT as well as the FORUPDATE clause.

The table i want to update is inner-joined to the "main" table (FWPPBATable).

treeBomQbds = pbaTableQbds.addDataSource(tableNum(FWPPBATreeBOM), tableStr(FWPPBATreeBOM));
treeBomQbds.joinMode(JoinMode::InnerJoin);
treeBomQbds.relations(false);
treeBomQbds.addLink(fieldNum(FWPPBATable, RecId), fieldNum(FWPPBATreeBOM, PBATable));
treeBomQbds.addRange(fieldNum(FWPPBATreeBOM, DataAreaId)).value(itemRange);

ttsbegin;
    
    while (qr.next())
    {
        pbaTable = qr.get(tableNum(FWPPBATable));
        treeBom = qr.get(tableNum(FWPPBATreeBOM));
        finishedGood = qr.get(tableNum(FWPPBATreeFinishedGood));

        // search for PBA's that have one route only
        select count(RecId) from treeOpr
            where treeOpr.PBATable == pbaTable.RecId;

        if(treeOpr.RecId == 1)
        {
            oldPbaTable = FWPPBATable::find(treeBom.FWIPBATablePreProd);
            prePbaTable = this.findValidPBA(treeBom);
            
            if (prePbaTable.RecId != oldPbaTable.RecId)
            {
                treeBom.selectForUpdate(true);
                treeBom.FWIPBATablePreProd = prePbaTable.RecId;
                treeBom.update();
            }
        }
    }
    
ttscommit;



Any ideas on this?

Regards,

Nils

*This post is locked for comments

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Hi Nils,

    You have to set the query to update. The call when you have fetched the record already is too late. You can also consider using another variable of this table and select the record based on the record ID of treeBOM.

  • Community Member Profile Picture
    on at

    Hi Andre,

    thanks for reply. Query provides a mothod called "userUpdate(bool)". Unfortunatelly this had no effect :-/.

    I think your second suggestion works.

    Regards

    Nils

  • Tayfun Sertan Yaman Profile Picture
    280 on at

    Not the query but you need to set the Query build data source's update() method to true, like qdbs.update(true), then it will work ok.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans