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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Can't update Purchline and PurchTable

(0) ShareShare
ReportReport
Posted on by 159

Hi everyone,

I want to update two fields in Purchline and when I debbugting the code i go in UPDATE method but it doesn't execute to the end and ExecuteByLine go to catch and nothing happnes. 

public void ExecuteByLine()

{
    try
    {
        while select firstOnly forUpdate _purchLine
            where _purchLine.dataAreaId == _areaId
                  && _purchLine.PurchId == _purchId
                  && _purchLine.InventTransId == inventTransId
        {
            _purchLine.InterCompanyOrigin = 0;
            _purchLine.InterCompanyInventTransId = "";
            _purchLine.update();
        }

    }
    catch
    {
        error(strFmt("Error! The operation is unsuccessful!"));
    }
}

When I try to update PurchTable  , the ExecuteByHeader doesn't go to catch mathed and everything looks fine but when I check what happened in SQL . The result is nothing.

public void ExecuteByHeader()
{
    try
    {
        while select forUpdate _purchTable
            where _purchTable.dataAreaId == _areaId
                  && _purchTable.PurchId == _purchId
        {
            ttsBegin;
            _purchLine.clear();
            _purchTable.InterCompanyOrigin = 0;
            _purchTable.InterCompanyCompanyId = "";
            _purchTable.InterCompanySalesId = "";
            _purchTable.InterCompanyOrder = 0;
            _purchTable.update();
            ttsCommit;
        }
    }
    catch
    {
        error(strFmt("Error! The operation is unsuccessful!"));
    }
}


Sometimes in debug mode throws this error:
_4C043904_.JPG

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,379 Most Valuable Professional on at

    Which line is throwing the error? Which kind of exception it is?

  • Vladislav Profile Picture
    159 on at

    Hi Sukrut ,

    my idea is to execute one of them according on the circumstances. I tried with ttsbegin and ttscommit , but nothing happend

    Thank you.

  • Vladislav Profile Picture
    159 on at

    Hi Martin Drab,

    By debbuging get to line with _purchLine.update(); and I mean this method doesn't execute it at all and after that go to catch. First throw my error and after that display this error from picture in debug tools -> Infolg . Also throw and this exception:
    Ax_5F00_error.PNG

    Regards,

    Vladislav

  • Verified answer
    Martin Dráb Profile Picture
    239,379 Most Valuable Professional on at

    You're missing the transaction. While select with firstOnly makes little sense. You have a filter for dataAreaId but AX will always filter by the current company anyway (either remove it, use crossCompany or changeCompany()). InventTransId uniquely identifies the line, therefore the filter on PurchId shouldn't be needed. Your code swallows the exception (which may be your intention as well as a bug). strFmt() without any placeholder to replace is useless and can be thrown away. 

    Try this:

    public void ExecuteByLine()
    {
        PurchLine purchLine;
        
        try
        {
            ttsBegin;
            
            select firstOnly forUpdate purchLine
                where purchLine.InventTransId == inventTransId
            
            if (purchLine)
            {
                purchLine.InterCompanyOrigin = 0;
                purchLine.InterCompanyInventTransId = "";
                purchLine.update();
            }
            
            ttsCommit;
    
        }
        catch
        {
            throw error("Error! The operation is unsuccessful!");
        }
    }

    Note that you could also use update_recordset instead of fetching the record and sending it back to database.

  • Vladislav Profile Picture
    159 on at

    Martin Drab ,

    the problem was ttsBegin and ttsCommit.I didn't put them on the right place.

    Thank you a lot of !

    And also one small question. I have form for this class, who I create only with class and how to attach here :

    2772.111.JPG

  • Martin Dráb Profile Picture
    239,379 Most Valuable Professional on at

    Please create a new thread for the new question not related to "Can't update Purchline and PurchTable" and explain it in detail there.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans