Looking for records that don't exist in AL and Business Central

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ม.ค. 2025

ความคิดเห็น • 15

  • @tedcjohnston
    @tedcjohnston ปีที่แล้ว

    Coming from NAV, we would call Validate on the Unit Price field as there's some logic there. Is this no longer the case in BC?

    • @Hougaard
      @Hougaard  ปีที่แล้ว

      Yes, as I also said in the video :)

  • @danialbrentsen8718
    @danialbrentsen8718 ปีที่แล้ว

    What you mentioned about the pageproperty “delayed insert” is actually very interesting. Most of the Pages (including standard Pages) have on several triggers Currpage.Update function. This messes up the delayed insert property, so the record is actually inserted Way before you expect it to be

    • @TheLamza
      @TheLamza ปีที่แล้ว

      This is because UpdatePropagation property of the subform is set to Both. e.g. when Unit Price of the Sales Line gets modified, Currpage.Update will push that change to the Sales document header page where it recalculates the totals.

  • @Katzen48
    @Katzen48 ปีที่แล้ว +1

    For the insert, I would probably go with something like this:
    Item.SetRange("No.", '123');
    Item.Init();
    Item."No." := '123';
    Filloutfields(Item);
    if not Item.Insert(true) then
    Item.ModifyAll("Unit Price", 233, true);
    This reduces the number of SQL executions for non-existing Items to one.
    Because of the "if" you can't profit from batching inserts, when you modify multiple records, but with a "Get" at the beginning the NST can't use batching, anyway.

    • @Hougaard
      @Hougaard  ปีที่แล้ว

      First of all, the NodifyAll is expensive to use for a single record and it does not support multiple fields, so I would never do that...

    • @Katzen48
      @Katzen48 ปีที่แล้ว

      @@Hougaard Agreed.
      For that single, presented use case, where you don't validate the field value, it would depend on, whether the modify-Trigger contains code and if you have an subscriber on OnModify.
      If neither is the case, you could drop the modify(true) and the modifyall will be converted into a 'update Item Set "Unit Price" = 233 Where "Code" = 123' SQL Statement with no Findset nor operation on the NST.
      But it highly depends on the situation.

    • @Hougaard
      @Hougaard  ปีที่แล้ว

      @@Katzen48 Still "ModifyAll" reduces the readability of the code and doesn't really make it better, so I would never use it that way :)

  • @sksyt5653
    @sksyt5653 ปีที่แล้ว

    Can we get BC dark mode 👀.

  • @henryeselmejor
    @henryeselmejor ปีที่แล้ว

    Erik could you explain what @Katzen48 explains?

    • @Hougaard
      @Hougaard  ปีที่แล้ว

      Not really, I don't think that is the right approach, see comment left for him...

  • @Katzen48
    @Katzen48 ปีที่แล้ว

    The "exist" is not in the video title.
    The title only says "Looking for records that doesn't..."

    • @GosuSalt
      @GosuSalt ปีที่แล้ว +3

      It's cuz it doesn't exist 😂

    • @Hougaard
      @Hougaard  ปีที่แล้ว

      Fixed