Why is OnAfterInsertEvent subscription triggered (twice) when opening a sales order?

markclemarkcle Member Posts: 65
Hi All

I have a code unit that has this line in it:
 [EventSubscriber(ObjectType::Table, Database::"Sales Line", 'OnAfterInsertEvent', '', true, true)]

It fires twice for every line when I open a sales order and the lines are displayed

Puzzled

Mark

Best Answer

Answers

  • JuhlJuhl Member Posts: 724
    Maybe temporary table is in use??
    Follow me on my blog juhl.blog
  • markclemarkcle Member Posts: 65
    Juhl wrote: »
    Maybe temporary table is in use??

    Possibly, but it's a subscription on Sales Lines (Database::"Sales Line"), so shouldn't generate events unless sales lines are inserted
  • JuhlJuhl Member Posts: 724
    It does.
    Thats why you ALWAYS check if its temporary, before running your code!!
    Follow me on my blog juhl.blog
  • markclemarkcle Member Posts: 65
    Juhl wrote: »
    It does.
    Thats why you ALWAYS check if its temporary, before running your code!!

    Thanks for reply. Still puzzled why the event would trigger on a temp table. how do I check if it's a temp table?
  • markclemarkcle Member Posts: 65
    Juhl wrote: »
    If not Rec.istemporary or RunTrigger then
    Exit;

    It also fires when run trigger is false. So check that as well.

    Could you explain a little more about the run trigger issue?
  • JuhlJuhl Member Posts: 724
    Insert(false)
    Insert(true)
    Follow me on my blog juhl.blog
Sign In or Register to comment.