0

Duplication when importing products

Hello
We have a local database and need to update product information by importing data from one database to another. The issue is that our current formula creates duplicates when importing, and we want to prevent that. We need the formula to update an existing product if it already exists based on a unique identifier (like the product number) and create a new product only if it does not exist. Additionally, images are not transferred via CSV, so we need to ensure that those are properly updated as well.

for j in select 'Source Table' do
    let articleNo := j.'Article No.';
    let existingRecord := first(select '3_Article' where 'Article No.' = articleNo);
    if not existingRecord then
        let newRecord := (create '3_Article');
        newRecord.('Article No.' := articleNo);
        newRecord.('Article name' := j.'Article name');
        newRecord.('Price per unit' := j.'Price per unit');
        newRecord.('Purchase price' := j.'Purchase price');
        newRecord.(Description := j.Description);
        newRecord.(Image := j.Image)
    else
        existingRecord.('Article name' := j.'Article name');
        existingRecord.('Price per unit' := j.'Price per unit');
        existingRecord.('Purchase price' := j.'Purchase price');
        existingRecord.(Description := j.Description);
        existingRecord.(Image := j.Image)
    end
end

Currently, we haven't found a better solution that effectively updates both the product information and the images. We need a method that ensures no duplicates are created, while also allowing us to add new products when needed. Any approach that allows both product details and images to be updated during import, while avoiding duplication, would be appreciated.

1 reply

null
    • Fred
    • 3 wk ago
    • Reported - view

    You are saying:

    if not existingRecord then
    

    doesn't work. You can try:

    let existingRecord := (select '3_Article' where 'Article No.' = articleNo);
    if count(existingRecord) = 0 then
    

    If that doesn't work. Is 'Article No.' in 3_Article a text or number field? Sometimes the import data type may seem obvious to us, but Ninox has a hard time processing it. So you can try putting text() or number() around variable articleNo.