Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

update_recordset statement not working. The same with while select forUpdate works..

Posted on by 1,085

Hi,

any known issues about this?

I've encountered a custom method which tries to update a set of record by joining 2 tables with the update_recordset statement. Something like:

update_recordset myTable1
                            setting [fieldsList]
                            join myTable2
                                where [conditions]

The instruction returns this error "could not update a record" and i can see this join doesn't retrieves anything.

If i do the same with a "while select forUpdate" statement, it works fine. The records are retrieved and updated.
Obviously this takes much more time than the update_recordset.

Any idea about this issue?

Thank you in advance

  • vv1984 Profile Picture
    vv1984 1,085 on at
    RE: update_recordset statement not working. The same with while select forUpdate works..

    The error message is in italian. I've tried to look for it in the label editor, but could not find the exact entry.

    But it is something like "could not update a record in table %1 .... SQL database error"

  • Verified answer
    vv1984 Profile Picture
    vv1984 1,085 on at
    RE: update_recordset statement not working. The same with while select forUpdate works..

    Yes guys, it seems that the division by zero throws that error on the update_recordSet statement.

    update_recordset myTable1

                               setting numericField/divisionField

                               join myTable2

                                   where [conditions]

    if divisionField equals zero, Ax returns the following:

    Cannot edit a record in myTable1 (myTable1Name). [...] SQLdatabase error.

  • Martin Dráb Profile Picture
    Martin Dráb 228,552 Most Valuable Professional on at
    RE: update_recordset statement not working. The same with while select forUpdate works..

    Divisiobn by zero obviously is a problem. Please do the check before even trying to run your query.

    First of all, try setting a fixed value (setting RevisionSalesQty = 42). If it works, use the field from the child record (setting RevisionSalesQty = revLine.RevisionPercent). If it works, add the expression (/revPercentDiv). That should give you a better idea what exactly doesn't work; trying to debug many things at once usually doesn't bring any result at all. I'm not sure that the last case is supported by update_recordset.

    Also, can you give us the error message?

  • vv1984 Profile Picture
    vv1984 1,085 on at
    RE: update_recordset statement not working. The same with while select forUpdate works..

    I've "translated" this update_recordSet into the while select below.

    The value "revLine.RevisionPercent/revPercentDiv" previously led to "division by zero" error inside the select while. Could be that the cause?

    Anyway, the update_recordSet was not retrieving anything...

    update_recordset salesLine_update
    setting RevisionSalesQty = revLine.RevisionPercent/revPercentDiv
    join revLine
    where !revLine.SalesId &&
    revLine.ItemGroupId == salesLine_update.ItemGroupId &&
    revLine.RevisionId == RevisionId &&
    salesLine_update.Runnumber == RSRun_loc.Runnumber;

    //This one works fine
     while select forUpdate salesLine_update
     join revLine
     where !revLine.SalesId &&
     revLine.ItemGroupId == salesLine_update.ItemGroupId &&
    revLine.RevisionId == RevisionId &&
     salesLine_update.Runnumber == RSRun_loc.Runnumber
    {

    if(revPercentDiv!=0)
        RevisionSalesQty = revLine.RevisionPercent/revPercentDiv;

    }

  • Suggested answer
    Faisal Fareed Profile Picture
    Faisal Fareed 10,794 User Group Leader on at
    RE: update_recordset statement not working. The same with while select forUpdate works..

    Hi win32,

    Please share your actual code which is working for while select statement and not with update_recordset then we will be able to find the exact missing point from there. For your reference I am sharing a small concept on update_recordset, it may help you but important to share your code.

    daxture.blogspot.com.au/.../all-about-updaterecordset.html

  • Martin Dráb Profile Picture
    Martin Dráb 228,552 Most Valuable Professional on at
    RE: update_recordset statement not working. The same with while select forUpdate works..

    Can you show us your actual code and copy the exact wording of the error message, please?

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,552 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,552 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans