tracylee
26th August 2015, 06:45
Hi,

I having a problem regarding to update latest data to another table when delete one data.

I have two session "A" and "B".
"A" is the data I want to delete.
"B" is the session only display the data from table "A".

Let said session "A" got 5 data.
Now I delete one data from there. On the same time, when finished to delete that data, session "B" will automatic update.

How to write the coding when I delete one data from Session "A" and automatic update session "B"?

I got wrote the coding as below. But it is only update the data before I delete the data. Please advise. Thanks.


choice.mark.delete:
after.choice:
update.data()

functions:

function update.data()
{
select tdsls313.*
from tdsls313 for update
where tdsls313.cono = :tdsls306.cono and tdsls313.pono = :tdsls306.pono and tdsls313.cofc = :tdsls306.cofc and tdsls313.rev = :tdsls306.rev
selectdo
ret5 = dal.change.object("tdsls313")
dal.set.field("tdsls313.cono", tdsls306.cono)
dal.set.field("tdsls313.pono", tdsls306.pono)
dal.set.field("tdsls313.cofc", tdsls306.cofc)
dal.set.field("tdsls313.item", tdsls306.item)
dal.set.field("tdsls313.rev", tdsls306.rev)
ret5 = dal.save.object("tdsls313")
selectempty
ret5 = dal.new.object("tdsls313")
dal.set.field("tdsls313.cono", tdsls306.cono)
dal.set.field("tdsls313.pono", tdsls306.pono)
dal.set.field("tdsls313.cofc", tdsls306.cofc)
dal.set.field("tdsls313.item", tdsls306.item)
dal.set.field("tdsls313.rev", tdsls306.rev)
ret5 = dal.save.object("tdsls313")

endselect

commit.transaction()
}

bhushanchanda
26th August 2015, 07:51
Hi,

Try calling your function in after.update.db.commit section.

after.update.db.commit:
update.data()

tracylee
26th August 2015, 08:43
Hi,

Try calling your function in after.update.db.commit section.

after.update.db.commit:
update.data()

Hi, thanks for your reply. I already try this after.update.db.commit session but result is same. Please advise. Thanks.

bhushanchanda
26th August 2015, 08:51
Hi,

Can you elaborate your exact problem? Did you try debugging your code? Can you check the values of table tdsls306 when you hit delete button? Does it go into selectdo? What is the return value of dal.save.object?

tracylee
26th August 2015, 09:54
Hi,

Can you elaborate your exact problem? Did you try debugging your code? Can you check the values of table tdsls306 when you hit delete button? Does it go into selectdo? What is the return value of dal.save.object?

Hi,

When I click the delete button, it prompt the message to ask "Delete the 1 selected record(s)?". And then I click "Yes" button. Then the script continue go through my update data function first and then only delete my selected data. Actually I wanted after delete the data only update my latest data without deleted data. Yes, it got go into table tdsls306 when hit delete button. Hope you understand what I explain. Please advise. Thanks for your help.

bhushanchanda
26th August 2015, 10:17
Hi,

Do you mean that, when you delete a record in table A, it should update the previous record data which is latest in table B?

If that is the case, you will need a select statement for table a to select the latest undeleted row and then call your update function

choice.mark.delete:
after.choice:
select tdsls306.*
from tdsls306
as set with 1 rows
update.data()
endselect

functions:

function update.data()
{
select tdsls313.*
from tdsls313 for update
where tdsls313.cono = :tdsls306.cono and tdsls313.pono = :tdsls306.pono and tdsls313.cofc = :tdsls306.cofc and tdsls313.rev = :tdsls306.rev
selectdo
ret5 = dal.change.object("tdsls313")
dal.set.field("tdsls313.cono", tdsls306.cono)
dal.set.field("tdsls313.pono", tdsls306.pono)
dal.set.field("tdsls313.cofc", tdsls306.cofc)
dal.set.field("tdsls313.item", tdsls306.item)
dal.set.field("tdsls313.rev", tdsls306.rev)
ret5 = dal.save.object("tdsls313")
selectempty
ret5 = dal.new.object("tdsls313")
dal.set.field("tdsls313.cono", tdsls306.cono)
dal.set.field("tdsls313.pono", tdsls306.pono)
dal.set.field("tdsls313.cofc", tdsls306.cofc)
dal.set.field("tdsls313.item", tdsls306.item)
dal.set.field("tdsls313.rev", tdsls306.rev)
ret5 = dal.save.object("tdsls313")

endselect

commit.transaction()
}

Though, I am not sure what kind of data you have in tdsls306. But, if you are simply calling your function, it will always have the values of deleted row.

tracylee
28th August 2015, 10:38
Hi,

Do you mean that, when you delete a record in table A, it should update the previous record data which is latest in table B?

If that is the case, you will need a select statement for table a to select the latest undeleted row and then call your update function

choice.mark.delete:
after.choice:
select tdsls306.*
from tdsls306
as set with 1 rows
update.data()
endselect

functions:

function update.data()
{
select tdsls313.*
from tdsls313 for update
where tdsls313.cono = :tdsls306.cono and tdsls313.pono = :tdsls306.pono and tdsls313.cofc = :tdsls306.cofc and tdsls313.rev = :tdsls306.rev
selectdo
ret5 = dal.change.object("tdsls313")
dal.set.field("tdsls313.cono", tdsls306.cono)
dal.set.field("tdsls313.pono", tdsls306.pono)
dal.set.field("tdsls313.cofc", tdsls306.cofc)
dal.set.field("tdsls313.item", tdsls306.item)
dal.set.field("tdsls313.rev", tdsls306.rev)
ret5 = dal.save.object("tdsls313")
selectempty
ret5 = dal.new.object("tdsls313")
dal.set.field("tdsls313.cono", tdsls306.cono)
dal.set.field("tdsls313.pono", tdsls306.pono)
dal.set.field("tdsls313.cofc", tdsls306.cofc)
dal.set.field("tdsls313.item", tdsls306.item)
dal.set.field("tdsls313.rev", tdsls306.rev)
ret5 = dal.save.object("tdsls313")

endselect

commit.transaction()
}

Though, I am not sure what kind of data you have in tdsls306. But, if you are simply calling your function, it will always have the values of deleted row.

Hi, Thanks for your reply. My problem already solved. I customize new function to delete the data and on the same time also can update the latest data into another table. Thanks for your help and suggestion. :)