fom_ln
10th July 2023, 16:31
Hello,

I am new to Baan/Infor Programming and extensibility. I am trying to delete a record in the tfgld018 after deleting a record from tfacp200.

After deleting the record from tfacp200 (session tfacp2600m000) the UI shows a message reporting: "Record not present in Documents for company", so the record is not deleted from tfgld018.

I tried to use db.update and using it the record is correctly updated. What am i missing?

This is the script in the after.destroy hook:

|delete the record from documents, does not work

select tfgld018.*

from tfgld018 for update

where tfgld018._index1 = {:tfacp200.ttyp, :tfacp200.ninv}

as set with 1 rows

selectdo

db.delete(ttfgld018, db.retry)

endselect

| update the document after the delete, this works

select tfgld017.*

from tfgld017 for update

where tfgld017._index1 = {:tfacp200.ttyp,:tfacp200.year}

selectdo

tfgld017.docn = tfgld017.docn - 1

db.update(ttfgld017, db.retry)

endselect

return(0)

Can you help me?

Thanks

OmeLuuk
17th July 2023, 16:27
When you want to delete something with the same reference, you might want to use the before.destroy hook instead (than the other delete is included in the same transaction, when the latter fails, the other one is also rolled back).

Remember in the after.destroy.object the current record values of your table have been destroyed so the fields are no longer available.

Another option is to store the references in the before destroy hook in "keep" variables representing the primary index and use them to select the record to delete.
Like I do in the sales order extension txesttdsls400:|common functions to be used in extension script.
function keep.some()
{
keep.orno = tdsls400.orno
}
function extern long before.destroy.object()
{
| hook code
keep.some()
return(0)
}
function extern long after.destroy.object()
{ boolean rbl
| hook code
rbl = tdslsdllo0001.remove.related.record(keep.orno)
return (0)
}

fom_ln
27th July 2023, 12:35
Hello,
I already tried both options, neither did work.