Developer forum

Forum » Integration » Using @Code and data[] for unmapped columns

Using @Code and data[] for unmapped columns

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

How do I use @Code to combine (or use) columns that are not in the destination mapping? As an example, let's say I wanted to set ProductName to ProductNumber_ProductName using @Code like this:

@Code(data["ProductNumber"]?.ToString() + "_" +  data["ProductName"]?.ToString())

For this to work, I assume the mapping needs to explicitly define the ProductNumber and ProductName columns. But when I try, I run into a few issues:

1. When I use a single column (ProductName) and set up the column as a @Code type, the UI automatically brings back and selects the Source column which I think shouldn't be there:

Then when I run the job, the @Code doesn't seem to be executed and the Name stays what it is in the source file.

2. If I use multiple columns, it fails at run time:


with the mapping defined as follows:

I get the same result whether ProductName / ProductNumber are active or not.

3. If I remove the columns from the mapping I get the same error.

 

So in summary: how do I use @Code to access multiple columns in the source provider and combine them into a single one?

Imar


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Imar,
what providers are you using? I tried to reproduce it with Xml -> Ecom provider job with a mappings like that and it worked for me:

I also have a source column set to ProductName when I enter the Code statement from your post, however in your mappings there is no source column set to ProductName, maybe that is the issue.

BR, Dmitrij

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Oh, I see. I thought Source needed to be empty as we're mapping from code, not a source column (like we do with others like Constant). As soon as I picked a column (it seems you can pick any) it started to work. Thanks!

Imar

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Is this by design or a bug? In Imar's example he is using the source from 2 different columns. Seems like he could have picked any random column just to trigger the functionality.

 
Rasmus Sanggaard Dynamicweb Employee
Rasmus Sanggaard
Reply
This post has been marked as an answer

Hi,

It is by design, but I agree that it’s a bit strange. I’ll create a user story and see if we can find another technical solution that isn’t functionally odd.

BR Rasmus Sanggaard

Votes for this answer: 1

 

You must be logged in to post in the forum