Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicolai Winch Kristensen 50 posts 70 karma points
    Jan 28, 2014 @ 12:21
    Nicolai Winch Kristensen
    0

    Scheduled import - and member groups...

    Hi there :-)

    Ive ssed this this great module quite some times now - thx :-)

    I might have a little more complex solution to do now ,  but therws one issue I dont know if it can solve?

    I have to configure a scheduled import from a csv file (export from outlook), to the umbraco member  section. In the export file, the group membership of each user, is written as numbers representing af membership if a group. (right now in one field in export.)

    My question is: can the sceduled import handle to update (sing on to and sign off) to right member groups based on that.? - And if not , is there a smart way to customize og code a solution for this part? (maybe changing the export file a bit?)

    Best Regards :-)

    Nicolai

     

     

     

     

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Jan 28, 2014 @ 13:12
    Richard Soeteman
    0

    Hi Nicolai,

    Great that you like CMSImport. You requirement is also possible but requires a little bit of coding. CMSImport comes with a small event system you can hook into. If you take a look at the code below. It wires up an event handler when starting the Umbraco application. Then on each record it checks for the role column in the data source. Based on that it will assign the role name to the member.

    You can tweak this to your own needs such as correct column name but should work directly when you use it in your project


        public class AutoAssignMemberGroups : ApplicationBase
        {
            public AutoAssignMemberGroups()
            {
                MemberImport.RecordImporting += MemberImport_RecordImporting;
            }

            void MemberImport_RecordImporting(object sender, RecordImportingEventArgs e)
            {
                var member = sender as Member;
                if (member != null)
                {
                    //Assuming Roles is the column in the datasource
                    string rolesCsv = string.Format("{0}", e.Items["Role"]);

                    foreach(string role in rolesCsv.Split(','))
                    {
                        //You might want to cache this
                        var memberGroup = MemberGroup.GetByName(role);
                        member.AddGroup(memberGroup.Id);
                    }
                }
            }
        }

     

    Best,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft