Developer forum

Forum » Integration » Data type issue in TableScript task

Data type issue in TableScript task

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

As part of my search for a way to import addresses, I tried TableScript (which I love BTW). I have the following code that essentially converts a user's external ID to its "internal" ID:

public class RemapUserIds : TableScript
{
    public override void ProcessInputRow(Mapping mapping, Dictionary<string, object> row)
    {
      var user = User.GetUserBySql(string.Format("SELECT * FROM AccessUser WHERE AccessUserExternalID = {0}", row["AccessUserAddressUserID"]));
      if (user != null)
      {
        row["AccessUserAddressUserID"] = user.ID.ToString();
      }
    }
    ...
}   

I must call ToString() on user.ID or else the job fails with an error about casting an int to a string. Why is this? I exected this to work without ToString() since AccessUserAddressUserID is an int in the database. Why the conversion to a string? The input row being a Dictionary<string, object> also implies you could store whatever the underlying data type needs to be, and not just strings. Does this apply to all input rows?

Thanks,

Imar

 


Replies

 
Jonas Krarup Dam
Reply
This post has been marked as an answer

Hi Imar,

I assume your source in this case is an XML file. When you have an xml file as source, every column in the source is of type "string".

when we expect an int as the source, of course  the casting is done automatically, but when we're expecting a string from the source, but are getting an int, there's going to be some casting missing :-)

Hope this makes sense.

Regards, Jonas

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

Hi Jonas,

Yewah, that makes sense now. So this more or less ties a TableScript implementation to a specific provider? I assume it would need to be a proper int if I was targeting the User Provider for example?

Thanks,

Imar

 
Jonas Krarup Dam
Reply

Hi Imar,

Well, I suppose it does limit it to source providers that have columns with the same name and type. I don't see a way to avoid that (but I've only spent about 30 seconds thinking about it, so it might be possible).

The data type of the target provider doesn't matter - the implementation handles all conversions, where possible.

Regards, Jonas

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Got it, that all makes sense. Thanks!

Imar

 

You must be logged in to post in the forum