# copyMatchingColumns copying PK to destination record

**URL:** <https://forum.servoy.com/t/copymatchingcolumns-copying-pk-to-destination-record/8620>\
**Category:** Classic Servoy\
**Created:** [January 18, 2008, 8:19pm UTC](https://forum.servoy.com/t/copymatchingcolumns-copying-pk-to-destination-record/8620 "2008-01-18T20:19:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanparrish](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@ryanparrish](https://forum.servoy.com/u/ryanparrish)\
**Post date:** [January 18, 2008, 8:19pm UTC](https://forum.servoy.com/t/copymatchingcolumns-copying-pk-to-destination-record/8620/1 "2008-01-18T20:19:06Z")

</div>

Servoy 3.5.3

I am having a problem with copyMatchingColumns() overwriting the PK of the destination record, which if I understand the documentation correctly it is not suppose to do this?

I have the following code…  
( I have autoSave = false because all PK’s are db identity)

```auto
var new_carton_foundset = databaseManager.getFoundSet(controller.getServerName(), 'carton');
var new_carton_record = new_carton_foundset.getRecord(new_carton_foundset.newRecord(false, true));
databaseManager.saveData();
databaseManager.copyMatchingColumns(current_carton_record, new_carton_record, true);

for (i=1; i <= current_carton_record.fk_carton_item_to_carton.getSize(); i++) {
    current_ci_record = current_carton_record.fk_carton_item_to_carton.getRecord(i);
    new_carton_record.fk_carton_item_to_carton.newRecord(false, true);
    databaseManager.saveData();
    new_ci_record = new_carton_record.fk_carton_item_to_carton.getRecord(new_carton_record.fk_carton_item_to_carton.getSelectedIndex());
    databaseManager.copyMatchingColumns(current_ci_record, new_ci_record, ['carton_item_quantity', 'id_carton']);
}

```

Now if i put a breakpoint right before the databaseManager.copyMatchingColumns(current\_ci\_record, new\_ci\_record, [‘carton\_item\_quantity’, ‘id\_carton’])) I see the PK for new\_ci\_record equal to something like ‘DbIdentValue3099306’, after the copyMatchingColumns() it gets set to the value of the current\_ci\_record PK, also column ‘carton\_item\_quantity’ gets copied over into new\_ci\_record even though it should have been excluded (id\_carton does seem to get excluded)

---

<div class="post-metadata">

**Author:** ![ryanparrish](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@ryanparrish](https://forum.servoy.com/u/ryanparrish)\
**Post date:** [January 21, 2008, 4:41pm UTC](https://forum.servoy.com/t/copymatchingcolumns-copying-pk-to-destination-record/8620/2 "2008-01-21T16:41:53Z")

</div>

I’m actually seeing some rather strange inconsistent behavior with copyMatchingColumns() when I try to exclude columns. Sometimes it seems to not overwrite ‘id\_carton’ like i mentioned it does (correct behavior), yet other times it does overwrite the values for no apparent reason.

Am I using this function correctly?

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 17, 2008, 10:02am UTC](https://forum.servoy.com/t/copymatchingcolumns-copying-pk-to-destination-record/8620/3 "2008-02-17T10:02:05Z")

</div>

Did you find the cause of this problem ??

I am using this construction too now.  
If there is still a problem i might have to work out another way to do this.

Regards,

Hans Nieuwenhuis

---

<div class="post-metadata">

**Author:** ![ryanparrish](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@ryanparrish](https://forum.servoy.com/u/ryanparrish)\
**Post date:** [February 25, 2008, 8:13pm UTC](https://forum.servoy.com/t/copymatchingcolumns-copying-pk-to-destination-record/8620/4 "2008-02-25T20:13:39Z")

</div>

The issue I mentioned in the first post seems to have resolved itself, not quite sure how though ![:?]( "Confused")  
And the second post where it was copying over items even though I told it not to still is hit or miss, so in that case after doing the databaseManager.copyMatchingColumns() I just ‘null’ out the ones I didn’t want to copy and that works every time ![:)]( "Smile")

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 26, 2008, 7:29am UTC](https://forum.servoy.com/t/copymatchingcolumns-copying-pk-to-destination-record/8620/5 "2008-02-26T07:29:48Z")

</div>

Can one of the Servoyans please comment on this ?

I am planning to use this feature a lot, so i would like to know if there is a known issue ?

Regards,

Hans Nieuwenhuis
