Name

sn_cmdb_int_util.CmdbIntegrationUserLookup

Description

Operation to lookup a user from sys_user using a user name or email address. Input user name, email (optional) Output user sys id

Script

var CmdbIntegrationUserLookup = Class.create();
CmdbIntegrationUserLookup.prototype = {
  initialize: function() {
  	this.matchField = gs.getProperty('glide.discovery.assigned_user_match_field');
  	this.USER_NAME_FIELD = "user_name";
  	this.EMAIL_FIELD = "email";
  },
  
  lookupUser: function(userName, email) {
  	var userSysId = "";
  	if (!gs.nil(this.matchField)) {
  		userSysId = this._querySysUser(this.matchField, userName);
  		if (!gs.nil(userSysId)) {
  			return userSysId;
  		}
  	}
  	if (!gs.nil(userName) && (gs.nil(this.matchField) || this.matchField.toLowerCase() != this.USER_NAME_FIELD)) {
  		userSysId = this._querySysUser(this.USER_NAME_FIELD, userName);
  		if (!gs.nil(userSysId)) {
  			return userSysId;
  		}
  	}
  	if (!gs.nil(email) && (gs.nil(this.matchField) || this.matchField.toLowerCase() != this.EMAIL_FIELD)) {
  		userSysId = this._querySysUser(this.EMAIL_FIELD, email);
  		if (!gs.nil(userSysId)) {
  			return userSysId;
  		}
  	}
  	return "";
  },
  
  _querySysUser: function(field, value) {
  	var gr = new GlideRecord("sys_user");
  	gr.addQuery(field, value);
  	gr.addQuery('active',true);
  	gr.query();
  	if (gr.next()) {
  		return gr.getUniqueValue();
  	}
  	return "";
  },

  type: 'CmdbIntegrationUserLookup'
};

Sys ID

62cbd616771130100dfa1bfaae5a99d0

Offical Documentation

Official Docs: