# onDrop method broken?

**URL:** <https://forum.servoy.com/t/ondrop-method-broken/21354>\
**Category:** Questions\
**Created:** [December 30, 2024, 8:52am UTC](https://forum.servoy.com/t/ondrop-method-broken/21354 "2024-12-30T08:52:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexander.sternadel](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@alexander.sternadel](https://forum.servoy.com/u/alexander.sternadel)\
**Post date:** [December 30, 2024, 8:52am UTC](https://forum.servoy.com/t/ondrop-method-broken/21354/1 "2024-12-30T08:52:05Z")

</div>

Hi everyone,

I’m following the servoy video “Drag and Drop within and between data grids” [https://www.youtube.com/watch?v=\_T7qEJfXEp8](https://www.youtube.com/watch?v=_T7qEJfXEp8)  
and found that it does not work on my installation. The result is either nothing, nothing with warnings or an error of mismatched type.

The difference to the video that I noticed is that in the most recend version the parameter calls for an array and that the paramaeter is in plural with an “s” at the end:

```auto
* Called when a row is dropped as a result of a drag-n-drop.
 *
 * @param {Array<JSRecord>} sourceRecords
 * @param {JSRecord} targetRecord
 * @param {JSEvent} event

```

Leaving the paramaters as they are or changing them to whats in the video does not work.  
The developer also gives out a warning:

```auto
The property sort_key is undefined for the type JSRecord

```

or an error

```auto
TypeError: Cannot call method "sort" of undefined

```

Does anyone have any clue on this?

Cheers  
Alexander

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [December 30, 2024, 9:25am UTC](https://forum.servoy.com/t/ondrop-method-broken/21354/2 "2024-12-30T09:25:13Z")

</div>

Hi Alexander,

which version of Servoy are you on? I’m having problems getting this to work on Servoy 2023.03 NG Client. However, it seems that things are partially working in your case.

sort\_key is the column you are using to sort the records. It may be called something different in your database table.  
sort is a standard method on a foundset, so it sounds like you code is not correctly referencing the foundset of your grid component.

hope this helps,

Christian

---

<div class="post-metadata">

**Author:** ![alexander.sternadel](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@alexander.sternadel](https://forum.servoy.com/u/alexander.sternadel)\
**Post date:** [December 30, 2024, 9:54am UTC](https://forum.servoy.com/t/ondrop-method-broken/21354/3 "2024-12-30T09:54:41Z")

</div>

Hi Christian,

I’m running 2024.9.1.4003 with NG-Grids on 2024.9.4

Naming of sort\_key is correct in my database. Checked it before posting. Type is INTEGER.  
Neither the sort method is working, nor simple caluclations like sort\_key + 1  
It seems like the function is not finding or using the foundset properly to add the correspoding record into (sourceRecords, targetRecord)

Is there a special way needed to place it in the parameter?  
I tried so far:

```auto
@param {Array<JSRecord>}
@param {Array<JSRecord<db:/pqi/documents>>}
@param {JSRecord<db:/pqi/documents>}

```

---

<div class="post-metadata">

**Author:** ![swingman](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/swingman/32/4536_2.png) [@swingman](https://forum.servoy.com/u/swingman)\
**Post date:** [December 31, 2024, 4:51pm UTC](https://forum.servoy.com/t/ondrop-method-broken/21354/4 "2024-12-31T16:51:15Z")

</div>

You need to work with the array of source records and the target record.  
The actual foundset is irrelevant here.

I would replace the placeholders with:

```auto
@param {Array<JSRecord<db:/pqi/documents>>} sourceRecords
@param {JSRecord<db:/pqi/documents>} targetRecord
@param {JSEvent} event

```

C

---

<div class="post-metadata">

**Author:** ![alexander.sternadel](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@alexander.sternadel](https://forum.servoy.com/u/alexander.sternadel)\
**Post date:** [January 2, 2025, 5:13am UTC](https://forum.servoy.com/t/ondrop-method-broken/21354/5 "2025-01-02T05:13:42Z")

</div>

I tried this setting of the placeholders already, but nothing seems to work.

````auto
sourceRecords.doc_sortkey = targetRecord.doc_sortkey + 1;
``` like in the tutorial does not update anything.

````

application.output(sourceRecords.doc\_sortkey,LOGGINGLEVEL.INFO);

```gives

```

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [January 2, 2025, 8:03am UTC](https://forum.servoy.com/t/ondrop-method-broken/21354/6 "2025-01-02T08:03:23Z")

</div>

sourceRecords is an array…

application.output(sourceRecords[0].doc\_sortkey,LOGGINGLEVEL.INFO);

---

<div class="post-metadata">

**Author:** ![alexander.sternadel](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@alexander.sternadel](https://forum.servoy.com/u/alexander.sternadel)\
**Post date:** [January 2, 2025, 8:26am UTC](https://forum.servoy.com/t/ondrop-method-broken/21354/7 "2025-01-02T08:26:08Z")

</div>

Thank you! That solved it…

But that also means that the video is outdated? Since the onDrop function now calls for an array and the video shows a JSRecord.
