Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Gliderecord Issue with Inactive User in Business Rule

JHPost
Tera Contributor

Hello, I am having an issue with a Business Rule where the GlideRecord query is only working with active records on the sys_user table.

 

I am aware of the User Query BR on the sys_user table that automatically appends an addActiveQuery line so that inactive user records don't show up. My question is, what can I add to the below script to ensure that it will pick up on inactive records without having to modify that User Query BR.

 

var usr = new GlideRecord('sys_user');
if (usr.get('email', current.email)) {
    gs.addErrorMessage('This email address is already in use. Please submit a <a href="/$pwd_reset.do?sysparm_url=ss_default">Password Reset Request.<a>');
    current.setAbortAction(true);
}
1 ACCEPTED SOLUTION

AnjalPDijo
Giga Guru

Hi @JHPost , please try the following approach:

To ensure your GlideRecord query includes inactive user records without modifying the default User Query Business Rule on the sys_user table, you can disable Business Rules using setWorkflow(false) and replace get() with a manual query:

var usr = new GlideRecord('sys_user');
usr.setWorkflow(false);
usr.addQuery('email', current.email);
usr.query();
if (usr.next()) {
    gs.addErrorMessage('This email address is already in use. Please submit a /$pwd_reset.do?sysparm_url=ss_defaultPassword Reset Request</a>.');
    current.setAbortAction(true);
}

This approach bypasses the automatic addActiveQuery() added by the User Query BR, allowing you to retrieve both active and inactive users.

Please let me know if this works for you or if you encounter any issues.

Regards,
Anjal

View solution in original post

2 REPLIES 2

AnjalPDijo
Giga Guru

Hi @JHPost , please try the following approach:

To ensure your GlideRecord query includes inactive user records without modifying the default User Query Business Rule on the sys_user table, you can disable Business Rules using setWorkflow(false) and replace get() with a manual query:

var usr = new GlideRecord('sys_user');
usr.setWorkflow(false);
usr.addQuery('email', current.email);
usr.query();
if (usr.next()) {
    gs.addErrorMessage('This email address is already in use. Please submit a /$pwd_reset.do?sysparm_url=ss_defaultPassword Reset Request</a>.');
    current.setAbortAction(true);
}

This approach bypasses the automatic addActiveQuery() added by the User Query BR, allowing you to retrieve both active and inactive users.

Please let me know if this works for you or if you encounter any issues.

Regards,
Anjal

JHPost
Tera Contributor

@AnjalPDijo  This absolutely works!

 

Thank you!