Baanboard.com

Baanboard.com (http://www.baanboard.com/baanboard/index.php)
-   Tools Development (http://www.baanboard.com/baanboard/forumdisplay.php?f=8)
-   -   Creating and saving a text field [Session Extension] (http://www.baanboard.com/baanboard/showthread.php?t=70390)

alex.bonutti 4th September 2017 11:13

Creating and saving a text field [Session Extension]
 
Hi all,
I'm developing a session extension with Tools 10.5 which should create and save a predefined text in purchase order footer. I've tried both via external variable or via database text field, text is created but I'm not able to commit the transaction and save it. This is a sample of my 4GL code:

...
file.tmp = creat.tmp.file$()
ft = seq.open(file.tmp,"w")

text_body = "Sample text"
ret = seq.puts(text_body, ft)
seq.close(ft)

ret = text.write("tdpur400.txtb", "6", "Purchase.", "Order footer.", tdpur400.orno, "", "text", "text", file.tmp)

ret = dal.change.object("tdpur400")
ret = dal.save.object("tdpur400")
if ret <> 0 then
abort.transaction()
ret = dal.get.error.message(error.mess)
message(str$(ret) & " - " & error.mess)
else
commit.transaction()
message("Footer text created for purchase order " & tdpur400.orno)
endif
...

dal.get.error.message return value is 1.
I made a few tries with DAL scripts

ret = dal.change.object("tdpur400")
dal.set.field("tdpur400.txtb", text_nr)
ret = dal.save.object("tdpur400")


or even db update funtions

db.update(ttdpur400, db.retry)

but transaction cannot be completed with DAL error

Record ... cannot be saved in table Purchase Orders in company ...

If I commit just the text.write function, a text is correctly saved in the database, but it can't be linked in my entity (which is a purchase order). Can someone help me?

Thanks,
Alex

alex.bonutti 4th September 2017 13:01

I was able to solve it by selecting the record and updating it via db.update, I was hoping to do it via DAL but I couldn't find the way.

JaapJD 4th September 2017 14:52

Also for an update via the DAL you need to select the record:
Code:

select  tdpur400.*
from    tdpur400 for update
where  tdpur400.orno = :tdpur400.orno
as set with 1 rows
selectdo
        ret = dal.change.object("tdpur400")
        dal.set.field("tdpur400.txtb", text_nr)
        ret = dal.save.object("tdpur400")
endselect



All times are GMT +2. The time now is 21:05.


vB.Sponsors
©2001-2017 - Baanboard.com - Baanforums.com