Skip to content

Instantly share code, notes, and snippets.

@jlrjr
Last active December 7, 2016 20:15
Show Gist options
  • Save jlrjr/47029ef5d5113e58efe70e425f62ffe5 to your computer and use it in GitHub Desktop.
Save jlrjr/47029ef5d5113e58efe70e425f62ffe5 to your computer and use it in GitHub Desktop.
Okta ServiceNow ActivityPack Bulk Update User with OktaID
//query Okta for all users (sys_users) that do not have Okta IDs
// this may take a while to run for large user counts
getOktaUserIDs();
function getOktaUserIDs() {
var users = new GlideRecord("sys_user");
if (!users.isValidField("x_okta2_actpack_okta_id")) {
gs.error("Okta ID (x_okta2_actpack_okta_id) does not exist on sys_user table");
return;
}
users.addNotNullQuery("email");
users.addNullQuery("x_okta2_actpack_okta_id");
users.query();
gs.info("Querying users: " + users.getEncodedQuery() + " = " + users.getRowCount());
var act = new x_okta2_actpack.OktaRESTActivity();
while (users.next()) {
// Get Okta user id if we find a matching email
var email = users.getValue("email");
try {
var id = act.getOktaUserIDFromFilter('profile.email eq "' + email + '"', false);
if (gs.nil(id))
continue;
users.setValue("x_okta2_actpack_okta_id", id);
users.update();
gs.info("Updated user " + email + " with Okta ID " + id);
} catch (err) {
gs.error("Error getting ID from Okta for user " + email, err);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment