I am struggling trying to copy a parent and associated children into a new record.
My parent table is "quotation_base" and the first field is "quote_number". My child table is "quote_items" and the first field is "quote_number", there is a one-to-many relationship and I have referential integrity turned on.
I have an xdialog popup and one of the buttons is "NO", when this is selected I need to create a copy of a previous quote but with a new quote number (autoincrement).
My xbasic looks like this:
if response=UI_NO_SELECTED then
'we need to create another quote with the
'same header and line items but with a new
'quote number
''XBasic
dim hdr as p
dim items as p
dim old_parent as b
dim count_items as n
dim i as n
hdr=table.current(1)
items=table.current(2)
count_items = count(quote_items->quote_number,GRP->quotation_base)
if count_items>0 then
dim records[count_items] as b
i=0
items.fetch_first()
while i<count_items
i=i+1
records[i]=items.record_data_get()
items.fetch_next()
end while
end if 'count_items>0
old_parent=hdr.record_data_get()
hdr.enter_begin()
' note, the quote_number is
' an autoincrement field
' a new quote_number is assigned by the field rule,
hdr.record_data_set(old_parent)
hdr.enter_end(.t.)
if count_items>0 then
for i=1 to count_items
items.enter_begin()
items.record_data_set(records[i])
items.quote_number=hdr.quote_number
items.enter_end(.t.)
next
end if ' count_items>0
parent.resynch()
end
When I run this I get an error
"property not found", "items.quote_number subelement not found" . Running debug, the count of the child records is fine and the parent record is successfully copied into a new parent record with a new quote number. The error is generated at the point where the code attempts to modify the quote number in the stored "old" child record before copying it into the new one.
The code is based on the example at learn alpha.com
My parent table is "quotation_base" and the first field is "quote_number". My child table is "quote_items" and the first field is "quote_number", there is a one-to-many relationship and I have referential integrity turned on.
I have an xdialog popup and one of the buttons is "NO", when this is selected I need to create a copy of a previous quote but with a new quote number (autoincrement).
My xbasic looks like this:
if response=UI_NO_SELECTED then
'we need to create another quote with the
'same header and line items but with a new
'quote number
''XBasic
dim hdr as p
dim items as p
dim old_parent as b
dim count_items as n
dim i as n
hdr=table.current(1)
items=table.current(2)
count_items = count(quote_items->quote_number,GRP->quotation_base)
if count_items>0 then
dim records[count_items] as b
i=0
items.fetch_first()
while i<count_items
i=i+1
records[i]=items.record_data_get()
items.fetch_next()
end while
end if 'count_items>0
old_parent=hdr.record_data_get()
hdr.enter_begin()
' note, the quote_number is
' an autoincrement field
' a new quote_number is assigned by the field rule,
hdr.record_data_set(old_parent)
hdr.enter_end(.t.)
if count_items>0 then
for i=1 to count_items
items.enter_begin()
items.record_data_set(records[i])
items.quote_number=hdr.quote_number
items.enter_end(.t.)
next
end if ' count_items>0
parent.resynch()
end
When I run this I get an error
"property not found", "items.quote_number subelement not found" . Running debug, the count of the child records is fine and the parent record is successfully copied into a new parent record with a new quote number. The error is generated at the point where the code attempts to modify the quote number in the stored "old" child record before copying it into the new one.
The code is based on the example at learn alpha.com
Comment