rduncan10
10th November 2015, 17:42
I'm trying to write a session that will add or update the item text (tiitm001.txta) when the user changes the signal code.

This works fine if there is already text in tiitm001.txta, but not if there is no text.

This is a type 1 form, main table is tiitm001.

The code I'm using:

choice.update.db:
after.choice:
do.update()

functions:
function do.update()
{
nr.lines = text.read("tiitm001.txta", language$,
kw1, kw2, kw3, kw4, tg, topt, new.txt, 0)

.... CODE TO UPDATE TEXT ....

if tiitm001.txta > 0 then
nr.lines = text.rewrite("tiitm001.txta", language$,
kw1, kw2, kw3, kw4, tg, topt, new.txt)
else
nr.lines = text.write("tiitm001.txta", language$,
kw1, kw2, kw3, kw4, tg, topt, new.txt)
endif
}


I thought text.rewrite() was supposed to add new text or replace existing, but that didn't work if there was no existing text, so I tried using both, but that did not work.

I tried changing "after.choice" in "choice.update.db" to "before.choice", but this caused a "TRANSACTION ON" error.

I wanted to use main.table.io instead, but that isn't working in this session at all.

bhushanchanda
10th November 2015, 18:45
Hi,

Did you do a commit after the update/insert? Did you checked with record locking? Also, there have been issues with the the file name variable declaration. How are you declaring it?

Many possible reasons for this behavior. Check the following related threads -

1 (http://www.baanboard.com/baanboard/showthread.php?t=265)
2 (http://www.baanboard.com/baanboard/showthread.php?t=61888)
3 (http://www.baanboard.com/baanboard/showthread.php?t=23194)
4 (http://www.baanboard.com/baanboard/showthread.php?t=9968)
5 (http://www.baanboard.com/baanboard/showthread.php?t=12237)

rduncan10
10th November 2015, 19:09
Thanks. I thought the update.db section would handle the commit, but I guess not. I did get it to work by using the after.update.db.commit:

after.update.db.commit:
if form.dirty <> 0 then
update.text()
endif

choice.modify.set:
before.choice:
form.dirty = 1

functions:
function update.text()
{
form.dirty = 0
nr.lines = text.read("tiitm001.txta", language$,
kw1, kw2, kw3, kw4, tg, topt, new.txt, 0)

.... CODE TO UPDATE TEXT ....

select tiitm001.*
from tiitm001 for update
where tiitm001._index1 = {:tiitm001.item}
selectdo
if tiitm001.txta > 0 then
nr.lines = text.rewrite("tiitm001.txta", language$,
kw1, kw2, kw3, kw4, tg, topt, new.txt)
else
nr.lines = text.write("tiitm001.txta", language$,
kw1, kw2, kw3, kw4, tg, topt, new.txt)
endif
db.update(ttiitm001, db.retry)
commit.transaction()
endselect
}