X++ – Inserting Data & select forupdate

  • X++ – Inserting Data & select forupdate

    Posted by DSC Communities on September 10, 2019 at 11:42 am
    • Curtis Watson

      Member

      September 10, 2019 at 11:42 AM

      Hey there,

      We’ve developed some components within D365 that generate some data and inserts it into tables.

      The approach taken leveraged the “select forupdate <tableBuffer>” methodology to insert data.

      In profiling the SQL statements, I have noticed that the “select forupdate <tableBuffer>” performs a SELECT statement against the target table; if modified to “select firstonly forupdate <tableBuffer>”, it results in a SELECT TOP(1) statement against the target table. This was resulting in performance degradation, where applying an index against [dataAreaId, partition] was needed, with include columns on all the table fields.

      I realize I’m probably doing something a bit incorrect here – I understand the “forupdate” clause would normally be used with a selection of record to actually update (i.e. “select forupdate <tableBuffer> where recId = <value>”).

      Is there a different approach to achieve this? Even in the Microsoft documentation, where it mentions the use of “.insert()” table method, there is still the “select forupdate <tableBuffer> statement (https://docs.microsoft.com/en-us/dynamicsax-2012/developer/insert-table-method).

      I know for fact the data I am trying to input is an insert; there would never be a need for an update. Is there any change I can make to avoid having to apply these other indexes?

      ——————————
      Curtis Watson
      StarTech.com
      London ON
      ——————————

    • Corey Vantilborg

      Member

      September 11, 2019 at 8:58 AM

      Curtis,

      Ā  Ā  Ā  Ā  You do not need to do the select forupdate when doing an insert.Ā  Ā That example from Microsoft is poor,Ā  it would select the entire CustTable for no reason.Ā 

      Ā  Ā  Ā  Ā  This would work just fine:

      static void Job7(Args _args)
      {
      TCI_ScanningSetup scanningSetup;
      scanningSetup.ItemBuyerGroupId = 'VMI';
      scanningSetup.insert();
      }

      Regards,
      Corey

      ——————————
      Corey Vantilborg
      ERP Analyst
      Tigercat International Inc.
      Brantford ON
      ——————————
      ——————————————-

    • vishal Dhawgaye

      Member

      September 25, 2019 at 5:04 PM

      I agree with Corey, you don’t have to user ‘forupdate’ for insert operation. you can also use ‘insert_recordset’ and ‘update_recordset’ while updating bunch of records. This gives better performance than ‘select forupdate’.

      ——————————
      vishal Dhawgaye
      Hitachi Solutions America, Ltd.
      ——————————
      ——————————————-

    DSC Communities replied 5 years, 11 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘X++ – Inserting Data & select forupdate’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!