Ajesh
2nd December 2009, 17:32
Hi

I want to use AFS to perform the following operation.

Copy a record in the User data and change the primary key to some other value and then save it.

I am using the following code

stpapi.put.field("ttaad2100m000", "ttaad200.user",similar.id)
stpapi.find("ttaad2100m000")
stpapi.application.option("ttaad2100m000", 1, 0, error.msg)
stpapi.put.field("ttaad2100m000", "ttaad200.user",form.id)
stpapi.put.field("ttaad2100m000", "ttaad200.name",form.name)
stpapi.put.field("ttaad2100m000", "ttaad200.uusr",form.uid)
stpapi.update("ttaad2100m000",1, error.msg)
stpapi.end.session("ttaad2100m000")

Where similar.user record is supposed to be searched and then a copy has to be performed and then the new values are put and saved.

I have used stpapi.application.option("ttaad2100m000", 1, 0, error.msg)
to access the copy command in the form 1.

But i cannot get the desired result. the result in the above case is that the existing record is updated.

I have also tried using stpapi.insert in place of update but it inserts record with blank fields.

Anybody with some insight

Regards
Shinoj

mark_h
2nd December 2009, 22:00
First this is the correct forum for AFS questions.

If you are just copying a record then just find the record, do some stpapi.get fields to get all the data, then stpapi.put to put all the fields. As far as I know there is not a stpapi command to do a copy of a record. The stpapi.application is for only those commands on the application menu.

Typically if I am doing something like this I just do select/update directly against the table. Not sure if there is more to this table to than that, but I would try that first. Then you could run ttaad4200m000 and just do a convert to runtime.

Ajesh
3rd December 2009, 07:43
First this is the correct forum for AFS questions.

If you are just copying a record then just find the record, do some stpapi.get fields to get all the data, then stpapi.put to put all the fields. As far as I know there is not a stpapi command to do a copy of a record. The stpapi.application is for only those commands on the application menu.


There are too many fields for the record. So putting all the fields is inconvenient. Thats why i was searching for the copy option.



Typically if I am doing something like this I just do select/update directly against the table. Not sure if there is more to this table to than that, but I would try that first. Then you could run ttaad4200m000 and just do a convert to runtime.



If i am updating the user data table directly i had found that convert to run time for the user doesnt happen as the conversion to run-time flag doesnt get set.

Maybe i could copy the record completely and then insert into the new one by using db.record.to.column etc,although i am not sure how to implement it
but this option i would keep if i am not able to implement it by AFS.

Do you think it would be possible to implement it by AFS?

goooch
3rd December 2009, 11:11
Shinoj,
I wonder if using of option number "-32" helps you

Regards

mark_h
5th December 2009, 02:05
Try what goooch recommended - never hurts. Also if it was a regular baan session there would be other options. As for copying at the table level use the record buffer - here is a sample from one of my programs:

string record.buf(1) based

rcd.ttpppc231 = record.buf
db.set.to.default(ttpppc231)
rcd.ttpppc231 = record.buf
tpppc231.cprj = tppro603.nprj
tpppc231.sern = get.next.tpppc231.sern(tppro603.nprj)
tpppc231.cspa = tppro603.csp1
tpppc231.quan = total.quan * somemultiplier | Quantity
tpppc231.amoc = total.amoc * somemultiplier | Total Amount
tpppc231.amos = total.amos * somemultiplier | Total Sales
tpppc231.loco = somelogin
tpppc231.desc = somelogin
db.insert(ttpppc231,db.retry)
commit.transaction()

This is just a snippet of code and the rcd.ttpppc231 = record.buf is actually in a different subroutine, which calls the other subroutine to insert records. I only set those fields that I need to change to insert a new record.