Skip to content

Instantly share code, notes, and snippets.

@lmarkus
Created January 7, 2016 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmarkus/2da64d37235c3c79b46e to your computer and use it in GitHub Desktop.
Save lmarkus/2da64d37235c3c79b46e to your computer and use it in GitHub Desktop.
How to import a subset of a large number of users into slack
var emailMatcher = /^.*\((.*)\)/; // name followed by enclosed email: akjshdkajshd (a@b.com)
var SKIP='0', UNSELECTED='-', INVITE='invite';
//Pick all unmapped user entries
var unmapped = $('#target_2 select')
.filter(function () {
return $(this).find('option:selected[value="'+UNSELECTED+'"]').length > 0;
});
//Set the default to "Skip"
unmapped.val(SKIP);
//Get the parent containers so we can match against the excel export
var parents = unmapped.closest('tr');
var incoming = {"email1@abc.com":true,"email2@abc.com":true,"email3@abc.com":true};
parents.each(function () {
var tr = $(this);
//pick email address from container (first child td):
var text = $(tr.children('td')[0]).html();
var email = emailMatcher.exec(text)[1];
if (incoming[email]) {
tr.find('select').val(INVITE);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment