roylansink
17th August 2023, 12:58
Hi,
I have a text number that acts as a default for a new record.

When a record is created, I want to duplicate that text number to a new text number and assign it to the newly created record.

I looked in the programmer's guide and found text.copy(), but this function copies (duplicates) the text from one table field to another. In my situation there is no table field, only a text number.

Can anyone point me in the right direction how to solve this?

mark_h
17th August 2023, 15:02
Can't you just create an empty text record and always copy that? I had a standard text that we setup that I always copied that. No reason you just can't have an empty text record to copy.

mark_h
17th August 2023, 15:37
I went and found the code I was thinking of - I did not actually use text.copy. What the program did was add standard text to a purchase order. So one session I allowed them to maintain the standard text and one session would copy these standard texts to and order. If the purchase order had no text I would use text.read to copy to file, then text.write to create it. If text already existed - then I would use text.read to put the current text in 1 file, then I would use text.read to put the new text into a 2nd file. Then append the two files together and use text.rewrite to copy them back into the purchase order. Kept purchasing from having to do manual cut and paste of standard text into purchase orders - we had like 20 to 30 of these, which were by site and program.

roylansink
17th August 2023, 17:05
Hi Marc,
Thank you for your reply. I understand and I tried to do the same, but I ran in to the same issue that I wanted to duplicate a text number and not a text field. I would expect there would be a function for that, but guess not...

But your reply gave me some new insights and I solved it by first querying the table tttxt002 and use the field tttxt002.ctxt in the function text.copy(tttxt002.ctxt,tssoc210.txtc,"","","","","","") to copy it too the designated text field.

Thanks!

JaapJD
17th August 2023, 17:18
Did you really got it working with

text.copy(tttxt002.ctxt,tssoc210.txtc,"","","","","","")
?
I assume you would need to do this:

text.copy("tssoc210.txtc","tttxt002.ctxt","","","","","","")

BTW you don't need to query tttxt002.ctxt. Just declare an external variable, give that the value of the textnumber you need to copy:

extern long my.text.variable
my.text.variable = 1234567
text.copy("tssoc210.txtc","my.text.variable","","","","","","")

mark_h
18th August 2023, 04:15
Just glad you solved it.