Business Rule on sys_email table that checks sys_user table?

Julia Howells
Giga Guru

I need to write a BR that checks if there is a value in the User ID [user_id] field in the Email [sys_email] record. If there is no value in the field, then move forward with the check. I have this portion ready. 

 

In the Email [sys_email] record, I need to use the User [user] field and search the following fields on the User [sys_user] table:

 

Email [email]
Email 2 [u_email_2]

 

If there is a match found, then I need to set the value of the Email [sys_email] record's User ID [user_id] field to the Sys ID of the located record in the search from the User [sys_user] table. Any ideas on how to write this?

1 ACCEPTED SOLUTION

Julia Howells
Giga Guru

I ended up going with this and it looks like testing is going well:

(function executeRule(current, previous /*null when async*/) {

	var grSysUser = new GlideRecord('sys_user');
	
	grSysUser.addQuery('email', current.user).addOrCondition('u_email_2', current.user);
	grSysUser.query();
	
		if (grSysUser.next()){
			current.user_id = grSysUser.sys_id;
		}

})(current, previous);

 Just adding in case anyone finds helpful.

View solution in original post

3 REPLIES 3

Faizeal Mohamed
Tera Guru

Hi,

 

The user_id value will appear only if User[user] field is not empty, you can easily dot walk the user_id and get the email.

 

May i know what are you trying to achieve here?

Julia Howells
Giga Guru

I ended up going with this and it looks like testing is going well:

(function executeRule(current, previous /*null when async*/) {

	var grSysUser = new GlideRecord('sys_user');
	
	grSysUser.addQuery('email', current.user).addOrCondition('u_email_2', current.user);
	grSysUser.query();
	
		if (grSysUser.next()){
			current.user_id = grSysUser.sys_id;
		}

})(current, previous);

 Just adding in case anyone finds helpful.

jeery
Giga Contributor

I found the real-world examples provided in this post to be particularly useful in understanding the concepts discussed. click here