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)

Update of multiple records

(0) ShareShare
ReportReport
Posted on by

Her's the code in which i want to select 2 records from the table using logical and condition && and then update the values accordingly if it satisfies both of the conditions. But it looks like i am writing something wrong. Kindly check this out.

class DisplayClass

{        

   /// <summary>

   /// Runs the class with the specified arguments.

   /// </summary>

   /// <param name = "_args">The specified arguments.</param>

   public static void main(Args _args)

   {        

       PTable pt;

      ttsbegin;

      select forupdate pt

           where pt.P_ID=="P101" &&

                 pt.P_ID=="P103";

       {  

           pt.PStatus = "Sold";

           pt.update();

           ttscommit;

       }

   }

}

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Update of multiple records

    Thanks a lot.  I was having a problem in my build. It worked now.

  • Verified answer
    Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    RE: Update of multiple records

    where pt.P_ID=="P101" || pt.P_ID=="P103" is the correct syntax. You either have a problem in data or in the way how you're testing the code.

    I'm pretty sure that we would have noticed if || operator didn't work.

  • Community Member Profile Picture
    on at
    RE: Update of multiple records

    Hee is the code what i did to update those records:

    class DisplayClass

    {        

       /// <summary>

       /// Runs the class with the specified arguments.

       /// </summary>

       /// <param name = "_args">The specified arguments.</param>

       public static void main(Args _args)

       {        

           PTable pt;

           update_recordset pt

               setting PStatus = "Confirmed"

               where pt.Pricee <= 120;

       }

    }

    So, what i am trying to say is like here i have put my condition on quantity ,similarly i want to put my condition on P_ID so how can i do that.?

  • Community Member Profile Picture
    on at
    RE: Update of multiple records

    And when i write (where pt.P_ID=="P101" || pt.P_ID=="P103"), then P101 is only updated.

  • Community Member Profile Picture
    on at
    RE: Update of multiple records

    I can update them separately defining their condition. But  the requirement is that i have to update multiple records in one line .

    like i want P101, P103, P105 , P107 all of their pstatus to be "sold". So how can i write that.

  • Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    RE: Update of multiple records

    You still have the same logical error there - no record can ever fulfil your condition, therefore nothing is updated.

    Ask yourself - can any ID be both "P101" and "P103" at the same time? Then please read my first reply once more.

  • Community Member Profile Picture
    on at
    RE: Update of multiple records

    One thing, here i also tried compiling the code without ttsbegin and commit , and also with them. But nothing worked.

  • Community Member Profile Picture
    on at
    RE: Update of multiple records

    Here's what i did as per your advice:

    class DisplayClass
    {
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
    PTable pt;

    ttsbegin;
    update_recordset pt
    setting PStatus = "Invoicedd"
    where pt.P_ID=="P101" &&
    pt.P_ID=="P103";
    ttscommit;


    }

    }


    However there are no errors.
    But the P101 and P103 are not changing their pstatus to invoicedd.
    Can you tell me why?

  • Suggested answer
    Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    RE: Update of multiple records

    You're almost there:

    PTable pt;
    
    ttsBegin;
    
    select forupdate pt
       where ...
    {  
        pt.PStatus = "Sold";
        pt.update();
    }
    
    ttsCommit;

    This would work, but it's inefficient. You don't need to fetch all 100 records from database; you merely want to update PStatus to Sold:

    PTable pt;
    
    update_recordset pt
        setting PStatus = "Sold"
        where ...;

    Also, please don't forget that AX has documentation and that you see thousand examples in the standard application.

  • Community Member Profile Picture
    on at
    RE: Update of multiple records

    Ok, but let me ask something. If i have 100 of records in my table, and i want to update some records accordingly, then how can i do it?

    So that in only one loop, the selected records are updated. Kindly help me with the code.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans