Copy across multiple database ID problem

Hello fellow Corvid coders

I’m in to abit of a technical problem, and running out of solution ideas.
I’m creating a nearly finished web tool, a proces work flow ‘you can call’ across three databases.
And the key fokus of using this tool created for my customer is simplicity at highest level, creating new order with only two action ‘pick and click’
The three databases are described as following-

  1. Warehouse static pick with occasional product information being changed etc.
    Informations are here being copied to an proces order.

  2. Processing and adding additional info etc. ‘Cache Database’
    After processing the specified order that were copied from warehouse pick, and approved it will be copied ones again to the final database and deleted from the corrent database.

  3. Record database
    As described, storage of the final order and path data.

Problem
While doing this method, we are copying everything, right from the start process of picking products and that’s fine…But however,
the ID is also coming across the cache database, and stored in the record base.

Here starts the problem.
While making a new order from the same warehouse and finishing proces, trying to store the order in record database will not go through because of the conflict with storing new data line with same ID.

Do any one know if we can code around this or worst, reconstructing the whole set up?
We are currently going around this by manual creating new order via cache database , but having people typing in manually proves a lot of wrong info are being insert to the order.
The copy code etc.

We are using is stated as followed:

import wixLocation from 'wix-location';
import wixData from 'wix-data';

export function button_onclick(event, $w) {
$w('#text31').show();
let toInsert = $w("#dataset1").getCurrentItem();
wixData.insert("procesdataset", toInsert)
.then( (results) => {
console.log("done adding item")
wixLocation.to("Hidden U R L");
} )
.catch( (err) => {
let errorMsg = err;
} );
}

Bonus help, I’m trying to figuring another solution about a smart and quick rearrange method nearly alike ‘drag & move’ on table in the proces cache, as the supervisor can move an order up the queue in proces.

Would like to thanks any comments on this in forward.

Hi,
As for the first issue, instead of copying everything (all the item information), you can query the database and copy only the needed information from the item (e.g. name of the warehouse and name of the product).

As for the supervisor to check orders and move them, you can watch this video tutorial for bookings flow and adapt it to your store.
You can also check if this tutorial will suit you better.

Just map your toInsert object before you insert it into the database. You can remove the _id field or just change it to have a different key and it will work just fine.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

Or you can delete the _id altogether like so:

delete toInsert._id;
wixData.insert("procesdataset", toInsert)
//...

Hi again fellows

Thanks a lot for answers

I have found that David’s solution was easiest to implant
so that’s what i’ve chosen to go with, and it works like intented
Big thanks for that.

But I also want to explore more on query codes which seems interesting.

The working (copy between databases without id) code is as follows

import wixData from 'wix-data';
export function Button1_onclick(event, $w) {
let toInsert = $w("#dataset1").getCurrentItem();
delete toInsert._id;
wixData.insert("#dataset2", toInsert)
.then( (results) => {
console.log("done adding item")
} )
.catch( (err) => {
let errorMsg = err;
} );

Happy 2020 Coding c’',)