Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Script Library

  Transferring members between webs
 
  chubbard posted this script:
  Here is a script file I have used a number of times to copy the members from one web to another:

//////////////////////////////////////////////////////////////////////////////
//    MEMBERS.WS
//        Script for copying members from one web to another.
//
//        Copy this script file into two different webs:
//            1. The "source" web which contains the members you wish to copy.
//            2. The "destination" web to which you will add the members.

//    GenScript  (run in the source web)
//        Run this function to generate a script function call for each
//        member in the source web.  Then paste the function calls into
//        a copy of the LoadMembers function below that runs in the
//        destination web.

webcall function GenScript()
    {
    if (!User.hasPermission(User.perm_ChangeMembership))
        {
        response.write("You do not have the necessary permissions to run this script.");
        return;
        }

    var i;
    response.write("<pre>\n");
    for (i = 0; i < 78; i++)
        response.write("/");
    response.write("\n//    ");       
    response.write("Paste the following script into Members.ws Import() function\n\n");

    var group;
    var arrGroups = new Array("Owner", "Administrators", "Staff", "Members", "Guests");

    var rs = new ResultSet("AddressBook", "UserName, Email", "*");
    while (rs.next())
        {
        if (rs.UserName.length == 0)
            continue;

        var mem = Members.getMemberFromEmail(rs.Email);
        if (mem == null)
            continue;

        for (i = 0; i < arrGroups.length; i++)
            {
            if (mem.isInGroup(arrGroups[i]))
                {
                group = arrGroups[i];
                break;
                }
            }

        if (group == "Owner")
            group = "Administrators";

        response.write("    AddMember('" + response.encodeHTML(mem.email) + "', '" + group + "');\n");
        }

    response.write("\n");       
    for (i = 0; i < 78; i++)
        response.write("/");
    response.write("\n</pre>");       
    }


//    LoadMembers  (run in the destination web)
//        Paste the script generated by a run of the GenScript function
//        into a copy of this function residing in the destination web.
//        Then run the resulting script to add all the members to the
//        destination web.

webcall function LoadMembers()
    {
    if (!User.hasPermission(User.perm_ChangeMembership))
        {
        response.write("You do not have the necessary permissions to run this script.");
        return;
        }

<ws:tags>
<pre>
<h2>Adding members to your web...</h2>
</ws:tags>

    //////////////////////////////////////////////////////////////////////////////////
    // Paste script here
    //  ------------>>

    //////////////////////////////////////////////////////////////////////////////////
    }


//    AddMember
//        Helper function for LoadMembers, which actually does the work
//        of adding a member and reporting status.

function AddMember (e, g)
    {
    try
        {
        var eOut = response.encodeHTML(e);
        var mem = Members.getMemberFromEmail(e);
        if (mem == null)
            {
            Members.add(e, g);
            response.write("<font color='green'>" + eOut + " -- SUCCESS member added to '" + g + "' group.</font>\n");
            }
        else if (mem.isInGroup("Owner"))
            {
            response.write("<font color='gray'>" + eOut + " -- NOCHANGE member is owner</font>.\n");
            }
        else if (!mem.isInGroup(g))
            {
            mem.changeGroup(g);
            response.write("<font color='green'>" + eOut + " -- SUCCESS member group changed to '" + g + "'.</font>\n");
            }
        else
            {
            response.write("<font color='gray'>" + eOut + " -- NOCHANGE already member of '" + g + "' group.</font>\n");
            }
        }
    catch (err)
        {
        response.write("<font color='red'>" + e + " -- ERROR member not added.</font>\n");
        }
    }

//////////////////////////////////////////////////////////////////////////////
 
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us