Page 1 of 1

Add / copy row with PK

Posted: Tue Oct 01, 2013 7:26 pm
by geologic

Hi

I have a table with one PK that is set at code with the concatenation of 2 fields. I make the concatenation at Row_inserting event:

function Row_Inserting($rsold, &$rsnew) {
$rsnew['CODE']=trim($rsnew['FIELD1'] . " " . $rsnew['FIELD2']);

It works when i add a new record but if i use de "copy" button, even i change the field1 and field2 (to create a new PK and new record) it sends me an error "duplicate primary key".

So, it works ok to new record but doesn't work for copy to a new record...

Regards


Re: Add / copy row with PK

Posted: Tue Oct 01, 2013 7:31 pm
by mobhar

Have you tried by using "Row_Inserted" instead?


Re: Add / copy row with PK

Posted: Wed Oct 02, 2013 1:30 am
by geologic

I cannot set a Primary key after the row has been inserted...


Re: Add / copy row with PK

Posted: Wed Oct 02, 2013 9:49 am
by mobhar

In "Row_Rendered" server event, please insert the following code:

if (CurrentPageID() == "add") {
$this->CODE->EditValue = "test"; // just a temporary value!
}

This will provide a temporary value for the CODE field, so that the code in your "Row_Inserting" will then work properly.


Re: Add / copy row with PK

Posted: Thu Oct 03, 2013 7:02 pm
by geologic

Great, worked!

Thanks