Developer forum

Forum » Integration » Conditional on Destination provider

Conditional on Destination provider

Maarten Schreuder
Reply

Hello,

We're trying to import a customer dataset into the DW database. Two of these data columns from the source that will be imported are usernames and passwords.

In our solution the user has to change his password after having logged in the first time, however, the import has to be able to run at any time, without overwriting the usernames and passwords after they have been altered by the user.

Is there a way that we can put a condition on the destination provider so that rows of which the user has changed is password will be ignored?

Sincerely,

Maarten Schreuder


Replies

 
Morten Snedker
Reply

Hi Maarten,

If user changes his information at frontend, you could add an additional user field of type boolean, ie "UserHasUpdated". If user changes his password/settings at frontend you can apply this field as a hidden field and set it to true. 

When the import job is run, you can set a conditional on the job, stating that field "UserHasUpdated" should be <>true. Then only rows having "UserHasUpdated" different from true will be updated. You can find additional information about the use of conditionals right here.

Hope you find the above useful.

 

Best regards
Morten Snedker

 
Maarten Schreuder
Reply

Hello Morten,

Thanks for your reply.

This is exactly what we've been trying to do, however clicking on the condition button in the import does not give me the option to add a condition. It has been my understanding that the conditional is added to the source, and not the destination?

Maarten Schreuder.

 
Morten Snedker
Reply
This post has been marked as an answer

You're quite right, Maarten - I stand corrected! :-)

In that case you need to write your own "stuff". In this case stuff will be a TableScript. A table script will feed you with an input row at a time. You can then manipulate the row before sending it forward again. In the example below we simply decide wether we should use the password from input, or use the one already stored in database:

using Dynamicweb;
using System.Linq;
using System.Collections.Generic;

namespace Dynamicweb.eCommerce.LiveIntegration.NotificationSubscribers
{
    public class DiscountTableScript : Dynamicweb.Data.Integration.TableScript
    {
        public override string ScriptingName
        {
            get
            {
                return "Processing script for Users";
            }
        }

        public override void ProcessInputRow(Dynamicweb.Data.Integration.Mapping mapping, Dictionary<string, object> row)
        {
            if (mapping.SourceTable != null)
            {
                string _password = GetUserPassword(row["AccessUserUserName"].ToString());
                if (_password != string.Empty)
                    row["AccessUserPassword"] = _password;
            }
        }

        private string GetUserPassword(string userName)
        {
            // If user has updated password, then return users' updated password as it is stored on the user in the database. 
            // Otherwise return empty string.

            string password = string.Empty;
            using (System.Data.IDataReader reader = Dynamicweb.Database.CreateDataReader(string.Format("SELECT AccessUserPassword,AccessUser_UserHasUpdated FROM AccessUser WHERE AccessUserUsername='{0}'", userName)))
            {
                while (reader.Read())
                {
                    if (Base.ChkBoolean(reader["AccessUser_UserHasUpdated"]) == true)
                    {
                        password = reader["AccessUserPassword"].ToString();
                    }
                }
            }
            return password;
        }
    }
}

 

It's a shot from the hip, so disclaimers are available. :-)
Compiling and putting the DLL on the solution, will expose it as an available script on Data Integration Jobs: http://screencast.com/t/rk1NhuPq

Best regards
Snedker

Votes for this answer: 1

 

You must be logged in to post in the forum