Accidentally deleted some sales header record with sales lines to it

Not sure why Navision let me delete a Sales Header with existing Sales Lines records.

Wouldn’t the SQL not allow this to happen?

Greg

Well, it should have deleted the sales lines as well. That’s what the OnDelete trigger is for.

Did you delete it with F4 or did you delete it with code? If you deleted it with code and called DELETE instead of DELETE(TRUE) the trigger would not fire and it delete the record without a problem, leaving the orphaned sales lines and dimensions and whatever else.

Accidentally?

You can always add a double check

OnDelete()
IF NOT CONFIRM(‘ARE YOU REALLY SURE YOU WANT TO DELETE THIS ORDER?’,FALSE)
THEN ERROR(’’);

Are you sure you accidentally deleted the sales header, casue if you pressed f4 mistakely then you must have got the confirmation message “Delete Sales Header”.

Or did you done something else ?

I was using DELETE in a report.

Greg

A quick way to figure out what lines exist without headers is add a temp Boolean flowfield to the sales line table.

Field Name: Header Exists
FieldClass: FlowField
CalcFormula: Exist(“Sales Header” WHERE (Document Type=FIELD(Document Type),No.=FIELD(Document No.)))

Now the lines that don’t have a Check in this field are missing the header & you can filter on those and mass delete to clean up the table.

Thanks.