How to fetch list of users where email before @ is not same as UPN (User Principal Name) before @

Priya Singh 2 2
Tera Contributor

How to fetch list of users where email before @ is not same as UPN (User Principal Name) before @

 

I want to fetch list of users where email before @ is not same as UPN before @ on user table but I am not able to achieve it by background script, it's returning all the users, please advise how I can get this data ?

2 REPLIES 2

Tanushree Maiti
Kilo Patron

Hi @Priya Singh 2 2 ,

 

This way we have fixed it .

( in our case , we are checking with lots of field in sys_user after the data analysis, you also please analyze your data and update the query and data accordingly). You can follow the same.

 

Create a Before insert,update BR on subscription table, which will  execute at the end (highest order) ..Give proper trigger condition.

 

Sample screen shot.

TanushreeMaiti_0-1778249716270.png

 

 

 

Sample code (if any modification is required ,do it):

 

(function executeRule(current, previous /*null when async*/ ) {
var op = current.operation();

if (op == "update") {
if (current.user_principal_name && current.user == '') {
var upnp = current.user_principal_name;

var userGrp = new GlideRecord('sys_user');
userGrp.addEncodedQuery('email=' + upnp + '^ORuser_nameSTARTSWITH' + upnp );
userGrp.orderByDesc('sys_created_on');
userGrp.query();

if (userGrp.next()) {
current.user = userGrp.sys_id.toString();
}
} else {

var upn = current.user_principal_name;

var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('email=' + upn + '^ORuser_nameSTARTSWITH' + upn );
userGr.orderByDesc('sys_created_on');
userGr.query();

if (userGr.next()) {
current.user = userGr.sys_id.toString();
}
}
}
})(current, previous);

 

Once done, Run the O365 job and  confirm whether your issue fixed or not.

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

After this let me know what % your are you able to populate user in s/w subscription table.. 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: