Developer forum

Forum » Integration » Import Excel to Ecom Provider

Import Excel to Ecom Provider

Michael Knudsen
Reply

I have a DW10 solution where all products are imported from Excel files and in some cases are an re-import done to update certain fields. Each product have an Excel_Key, which can be the same on multiple products and in that case I want all products with the Excel_Key to be updated.

I can map key coulmns in my import job to 'ProductLanguageId' + 'Excel_Key', but it returns a dublicated key error.

Has anyone a solution to this problem?

EcomProducts could have data like:
ProductId              ProductLanguageId  ProductNumber      Excel_Key        Data_Field
ImportedPROD1   DAN                         123456                    123456-2022    xyz
ImportedPROD2   DAN                         123456-2022           123456-2022    xyz

Br. Michael Knudsen


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

> Has anyone a solution to this problem?

I think you do, as we discussed this before :-) https://doc.dynamicweb.com/forum/integration/integration/update-stock-in-multi-language-site

It worked for me back then on DW9 with the DynamicwebProvider and an empty default language.

Imar

 

 
Michael Knudsen
Reply

Hello Imar,

- seems not to work on DW10 even I have removed the <DefaultLanguage> from the import job, since it isn't possible to 'empty' the default language on the Ecom Provider. 

Maybe because it was the Dynamicweb Provider and not the Ecom Provider back then?

Br. Michael Knudsen

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Michael,
can you check the option "Discard duplicates" and see if it will work for you?
BR, Dmitrij

 
Michael Knudsen
Reply

Hello Dmitriy,

- still doesn't work even I have checked "Discard duplicates" in combination with "Update only existing records" or "Update only existing products" same failure: Cannot insert duplicate key in object 'dbo.EcomProducts'. The duplicate key value is (ImportedPROD7946, DAN, )

Br. Michael Knudsen

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Michael, 

I am finding it hard to see that you can obtain what you want without a staging table (which are very commonly used). And it doesn't really take that many steps.

  1. Create staging table
  2. Create SQL View that will combine visma data with EcomProduts - and let this be you new source
  3. Setup import job that imports from your Excel to the staging table,
    1. You may want to check the checkbox "Remove missing rows after import in the destination tables only", as this will ensure having the staging table contain only what is imported in current import, clearing obsolete rows.
  4. Setup the final job that imports from staging table (SQL Provider) to EcomProducts (Ecom Provider)

 

1) Creating staging table - here named 'VISMA' (you can do this from Firehose)

The table is based on the schema of your current import job.

CREATE TABLE [dbo].[VISMA]
(
    [ProductVariantId]                         nvarchar(255) NULL,
    [ProductLanguageId]                        nvarchar(50)  NULL,
    [VISMA_DK_KEY]                             nvarchar(255) NULL,
    [ProductName]                              nvarchar(500) NULL,
    [ProductCategory|Product|ProductType]      nvarchar(255) NULL,
    [ProductCategory|Wine|Vintage]             nvarchar(255) NULL,
    [ProductCategory|Wine|ABV]                 nvarchar(255) NULL,
    [ProductCategory|Wine|Size]                nvarchar(255) NULL,
    [ProductCategory|Wine|ServingTemperature]  nvarchar(255) NULL,
    [ProductCategory|Wine|Closure]             nvarchar(255) NULL,
    [ProductCategory|Wine|Country]             nvarchar(255) NULL,
    [ProductCategory|Wine|Region]              nvarchar(255) NULL,
    [ProductCategory|Wine|District]            nvarchar(255) NULL,
    [ProductCategory|Wine|Denomination]        nvarchar(255) NULL,
    [ProductCategory|Wine|Appellation]         nvarchar(255) NULL,
    [ProductCategory|Wine|Classification]      nvarchar(255) NULL,
    [ProductCategory|Wine|Vineyard]            nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVariety1]       nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVarietyPct1]    nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVariety2]       nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVarietyPct2]    nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVariety3]       nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVarietyPct3]    nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVariety4]       nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVarietyPct4]    nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVariety5]       nvarchar(255) NULL,
    [ProductCategory|Wine|GrapeVarietyPct5]    nvarchar(255) NULL,
    [SalesUnitEAN]                             nvarchar(255) NULL,
    [SalesUnitLength]                          nvarchar(255) NULL,
    [SalesUnitWidth]                           nvarchar(255) NULL,
    [SalesUnitHeight]                          nvarchar(255) NULL,
    [SalesUnitNetWeight]                       nvarchar(255) NULL,
    [SalesUnitGrossWeight]                     nvarchar(255) NULL,
    [CartonUnitEAN]                            nvarchar(255) NULL,
    [CartonUnitLength]                         nvarchar(255) NULL,
    [CartonUnitWidth]                          nvarchar(255) NULL,
    [CartonUnitHeight]                         nvarchar(255) NULL,
    [CartonUnitNetWeight]                      nvarchar(255) NULL,
    [CartonUnitGrossWeight]                    nvarchar(255) NULL,
    [CartonUnitQty]                            nvarchar(255) NULL,
    [PalletUnitEAN]                            nvarchar(255) NULL,
    [PalletUnitLength]                         nvarchar(255) NULL,
    [PalletUnitWidth]                          nvarchar(255) NULL,
    [PalletUnitHeight]                         nvarchar(255) NULL,
    [PalletUnitNetWeight]                      nvarchar(255) NULL,
    [PalletUnitGrossWeight]                    nvarchar(255) NULL,
    [PalletUnitCartonsPerLayer]                nvarchar(255) NULL,
    [PalletUnitCartonsPerPallet]               nvarchar(255) NULL
);

For the ease of example, I've set all to nvarchar.

 

2) Create view that will be your new source (you can do this from Firehose)

CREATE OR ALTER VIEW [dbo].[VISMA_ProductImport]
AS
SELECT
    p.[ProductId],
    p.[ProductVariantId],
    p.[ProductLanguageId],
    p.[ProductNumber],
    v.[VISMA_DK_KEY],
    v.[ProductName],
    v.[ProductCategory|Product|ProductType],
    v.[ProductCategory|Wine|Vintage],
    v.[ProductCategory|Wine|ABV],
    v.[ProductCategory|Wine|Size],
    v.[ProductCategory|Wine|ServingTemperature],
    v.[ProductCategory|Wine|Country],
    v.[ProductCategory|Wine|Region],
    v.[ProductCategory|Wine|District],
    v.[ProductCategory|Wine|Denomination],
    v.[ProductCategory|Wine|Appellation],
    v.[ProductCategory|Wine|Classification],
    v.[ProductCategory|Wine|Closure],
    v.[ProductCategory|Wine|GrapeVariety1],
    v.[ProductCategory|Wine|GrapeVarietyPct1],
    v.[ProductCategory|Wine|GrapeVariety2],
    v.[ProductCategory|Wine|GrapeVarietyPct2],
    v.[ProductCategory|Wine|GrapeVariety3],
    v.[ProductCategory|Wine|GrapeVarietyPct3],
    v.[ProductCategory|Wine|GrapeVariety4],
    v.[ProductCategory|Wine|GrapeVarietyPct4],
    v.[ProductCategory|Wine|GrapeVariety5],
    v.[ProductCategory|Wine|GrapeVarietyPct5],
    v.[SalesUnitEAN],
    v.[SalesUnitLength],
    v.[SalesUnitWidth],
    v.[SalesUnitHeight],
    v.[SalesUnitNetWeight],
    v.[SalesUnitGrossWeight],
    v.[CartonUnitEAN],
    v.[CartonUnitLength],
    v.[CartonUnitWidth],
    v.[CartonUnitHeight],
    v.[CartonUnitNetWeight],
    v.[CartonUnitGrossWeight],
    v.[CartonUnitQty],
    v.[PalletUnitEAN],
    v.[PalletUnitLength],
    v.[PalletUnitWidth],
    v.[PalletUnitHeight],
    v.[PalletUnitNetWeight],
    v.[PalletUnitGrossWeight],
    v.[PalletUnitCartonsPerLayer],
    v.[PalletUnitCartonsPerPallet]
FROM [dbo].[VISMA] AS v
INNER JOIN [dbo].[EcomProducts] AS p
    ON p.[VISMA_DK_KEY] = v.[VISMA_DK_KEY]
   AND p.[ProductLanguageId] = v.[ProductLanguageId]
WHERE NULLIF(v.[VISMA_DK_KEY], N'') IS NOT NULL
  AND NULLIF(v.[ProductLanguageId], N'') IS NOT NULL;
 

With this view you will have a source with the unique keys from EcomProducts that you need. Let the native key columns be your key in the final import job that you set up (point 4):

  • ProductId
  • ProductVariantId
  • ProductLanguageId

The view will list all product rows having the visma_key(s) in current Excel - and will have the unique composite key you're currently missing.

Now setup the final job that uses SQL Provider as source - this provider will give you access to SQL Views, and let it point to your view, in this example named 'VISMA_ProductImport'. 

Hope the above is useful.

/Snedker

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Michael,
could you try to set the ProductId column as "create only" like that and check if it works?

BR Dmitrij

 
Michael Knudsen
Reply

woops.

 
Michael Knudsen
Reply

Hello Dmitriy,

- just for your information are the solution been upgraded to DW10.29.6, and setting both ProductId and ProductVariantId to "Don't overwrite" have helped on some of the Excel files, but it still fails on others.

Here is an example of failed Excel data:

ProductId: ""
ProductVariantId: ""
ProductLanguageId: "DAN"
ProductNumber: "2007136"
VISMA_DK_KEY: "2007136-2024"

- while we currently have these two products:

The import job fails with error message below, even the 2007136-2024 (VISMA_DK_KEY) isn't in the database! Don't understand why it think ProductNumber (2007136) should be unique?
 Cannot insert duplicate key in object 'dbo.EcomProducts'. The duplicate key value is (ImportedPROD5467, DAN, )

If I look closer to the error message (SQL part), I find it strange that ProductVariantId still are in the SQL even it's not part of the key coulmns?

update [dbo].[EcomProducts] 
set [SalesUnitEAN]=[dbo].[EcomProductsTempTableForBulkImport1].[SalesUnitEAN]...
where
 [dbo].[EcomProducts].[ProductVariantId]=[dbo].[EcomProductsTempTableForBulkImport1].[ProductVariantId] and
 [dbo].[EcomProducts].[ProductLanguageId]=[dbo].[EcomProductsTempTableForBulkImport1].[ProductLanguageId] and
 [dbo].[EcomProducts].[VISMA_DK_KEY]=[dbo].[EcomProductsTempTableForBulkImport1].[VISMA_DK_KEY] ;

 

PS. would it be possible somehow to keep the EcomProductsTempTableForBulkImport1 for debugging?

Br. Michael Knudsen

 

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Michael,
when the ProductId is empty the EcomProvider is trying to find the existing product using the source ProductNumber then ProductName unless the option "Use strict primary key matching" is on. It can not leave the ProductId column as empty, so if no product found then the auto generated ProductId like ImportedProd%% will be used.
So could you try to enable the "Use strict primary key matching" option in the Ecom destination provider (then only the ProductLanguageId and Excel_Key columns will be used)?

If ProductVariantId column is not in the column mappings list the EcomProvider adds this column as a PK column/Key column to the mapping (as it is PK in the database), so that is why it appears in the sql query where part.

Unfortunately, no. There is no setting to keep the temp tables. EcomProductsTempTableForBulkImport{n} (where {n} is the mapping's id, so 1 means the second mapping in the job) is created at the start of the run. The Ecom provider always drops it when the job ends, whether the job succeeded or failed. The drop happens in the writer's cleanup step, and you can't switch it off or override it from a custom provider.

The table is a normal table, not a #temp table, so you can read it from another session while the job runs. The flow is:

  1. The source rows are bulk-copied into the temp tables. The log shows "Finished import to temporary table for EcomProducts." when that is done.
  2. The job updates the products information and opens a transaction to move the data into EcomProducts.
  3. The temp tables are dropped.

To get a copy you can inspect afterwards, run this script in SSMS against the solution database, then start the job. It waits for the table to appear, keeps a snapshot while rows are still being added, and stops when the table is dropped:

IF OBJECT_ID('dbo.Debug_EcomProductsTemp') IS NOT NULL DROP TABLE dbo.Debug_EcomProductsTemp;

WHILE OBJECT_ID('dbo.EcomProductsTempTableForBulkImport1') IS NULL
    WAITFOR DELAY '00:00:00.200';

DECLARE @last int = -1, @now int;
WHILE OBJECT_ID('dbo.EcomProductsTempTableForBulkImport1') IS NOT NULL
BEGIN
    BEGIN TRY
        SELECT @now = COUNT(*) FROM dbo.EcomProductsTempTableForBulkImport1 WITH (NOLOCK);
        IF @now <> @last
        BEGIN
            IF OBJECT_ID('dbo.Debug_EcomProductsTemp') IS NOT NULL DROP TABLE dbo.Debug_EcomProductsTemp;
            SELECT * INTO dbo.Debug_EcomProductsTemp FROM dbo.EcomProductsTempTableForBulkImport1 WITH (NOLOCK);
            SET @last = @now;
        END
    END TRY
    BEGIN CATCH
        BREAK; -- table was dropped between the check and the read
    END CATCH
    WAITFOR DELAY '00:00:00.500';
END

SELECT COUNT(*) AS CapturedRows FROM dbo.Debug_EcomProductsTemp;

Change the 1 suffix if you're interested in another mapping. After the job, Debug_EcomProductsTemp holds the data as the provider prepared it, and you can check it for the duplicate key, for example:

SELECT ProductLanguageId, Excel_Key, COUNT(*)
FROM dbo.Debug_EcomProductsTemp
GROUP BY ProductLanguageId, Excel_Key
HAVING COUNT(*) > 1;

This is for debugging on a test or staging database, not something to leave running in production. If a built-in "keep temp tables" option for debugging would help, please add it as a feature request and we'll look at it.

BR, Dmitrij

 
Michael Knudsen
Reply

Hello Dmitriy,

- it seems the "Use strict primary key matching" option on the distination provider did the trick :-) I have removed all other options except "Create missing groups".

BTW: the description of "Use strict primary key matching" dosn't mention anything about inserts and updates, so perhaps an update on this is needed?
Deletes rows from each destination table individually, based on whether they are present in the corresponding source table. This setting looks at each table separately and removes rows missing from the source for that specific table

Br. Michael Knudsen

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Michael.

You have a 1:N between visma_key and product rows. Double check that category fields for all products are updated. I am not sure that they will.

/Snedker

 
Michael Knudsen
Reply

Thanks for bringing that to my attention, Morten; you’re absolutely right—the product category fields aren't updating across the products, which is pretty critical!

So there is still a problem :-|

Br. Michael Knudsen

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Michael,
This is a limitation of the Ecom destination provider one source row → one target product. As a workaround: try to use the staging-table + SQL View approach from Morten reply earlier in this thread. Consider the view so it produces one row per existing ProductID that shares the key (i.e. join visma_key to EcomProducts and output a row per match), then import using the actual ProductID as the key column. That makes the match 1:1 per row and all N products get updated. There is an article about the views here: Alternatives to Applying Code in You Integration Flow

BR, Dmitrij

 
Michael Knudsen
Reply

Hello Dmitriy,

- I'm (not) going to explain the purchasing dept. that they need to do a little workaround in order to import 'basic' Excel data, before data is updated correctly in DynamicWeb.

The EcomProvider are doing so much 'black box' magic, so it's just a shame that it doesn't do its job properly. Or atleast as I like it to behave :-)

Br. Michael Knudsen

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Michael,
I have created a new task to implement that: #29691. So there will be a new option "Update all existing products matching the key columns" under Edit options on a table mapping in the EcomProvider destination job.
BR, Dmitrij

 
Michael Knudsen
Reply

Hello Dmitriy,

- that's wonderful news, thanks!  I'm looking forward to try it out, once it hits R1.

Br. Michael Knudsen

 

You must be logged in to post in the forum