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

While select forupdate

(0) ShareShare
ReportReport
Posted on by

Hi I have this while select. What I want is to check if JournalNum from NCIntegrationJournalTable exists in NCIntegrationJournalTrans. And if just 1 of the selected records in  NCIntegrationJournalTrans has something in its ErrorLog field, then we must not do anything, else if there are nothing in ErrorLog, the journal will be posted.

 

As it is now, if just 1 of the records has ErrorLog=="", then it will post all of the records as if they are all ok, even if the others has error. And thats not correct.

 

    while select forupdate NCIntegrationJournalTable
        exists join ncIntegrationsJournalTrans

        where ncIntegrationsJournalTrans.JournalNum == NCIntegrationJournalTable.JournalNum &&
        ncIntegrationsJournalTrans.ErrorLog == ""
    {
        ttsBegin;
           NCIntegrationJournalTable.Posted = true;
           NCIntegrationJournalTable.update();
        ttsCommit;
    }

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at
    RE: While select forupdate

    Change it to notExists join where ErrorLog != "". So you only update those where no errors are found.

    On another note you should change this to update_recordset.

  • Community Member Profile Picture
    on at
    RE: While select forupdate

    Hi Jens

    Thanks for your response.

    I dont update anything in ncIntegrationsJournalTrans, where Errorlog is. I use ErrorLog as my criteria. I only update 1 row in NCIntegrationJournalTable, based on the criteria I have set. I just want my where clause to check, if just 1 row in ncIntegrationsJournalTrans, where errorlog != "", then it should not update the row in NCIntegrationJournalTable.

  • Community Member Profile Picture
    on at
    RE: While select forupdate

    Yes, so as I said you have to use a not exists join with exactly the clause I mentioned.

    Then only table records where no trans record with ErrorLog exists will be updated.

  • Community Member Profile Picture
    on at
    RE: While select forupdate

    Jens

    I have tried to demonstrate it in the attached image.

    7532.Screenshot_5F00_3.png

    Correction:

    The JournalNum in the NcIntegrationTable must be 546 and NOT 456.

  • duy.dang Profile Picture
    65 on at
    RE: While select forupdate

    According to me, it will be easy with below logic:

    Select NCIntegrationJournalTable on your condition.

     After that, with receiving result, you go to check condition in ncIntegrationsJournalTrans.

     if it 's equal you condition, you just update on selected NCIntegrationJournalTable.

    Finally, if it runs as you want, you may write a complex statement like you said.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: While select forupdate

    What is the issue with my solution? It should work. Please share your code with my implemented suggestion. I don't understand.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans