Business Rule: Show info message text based on queried value

Desmo
Mega Guru

Hello Community,

 

Following is a business rule to check for duplicate values in the sys_user table during insert. If duplicate is found, abort action. The script is working. 

 

I am looking for assistance scripting the gs.addInfoMessage to show what field was found to be a duplicate (User ID or Email), e.g. User with this <user_name> already exists, User with this <email> already exists.

 

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

    var grUsr = new GlideRecord('sys_user');
	grUsr.addQuery('user_name', current.user_name).addOrCondition('email', current.email);
    grUsr.query();

    if (grUsr.hasNext()) {
        current.setAbortAction(true);
        gs.addInfoMessage("User with this information already exists");

    }

})(current, previous);

 

Thank you.

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

try below (you can add value anywhere I added it to the end)

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

    var grUsr = new GlideRecord('sys_user');
    grUsr.addQuery('user_name', current.user_name).addOrCondition('email', current.email);
    grUsr.query();

    if (grUsr.next()) {
        current.setAbortAction(true);
        if (grUsr.user_name == current.user_name) {
            gs.addInfoMessage("User with this user id already exists " + current.user_name);
        } else if (grUsr.email == current.email) {
            gs.addInfoMessage("User with this email already exists " + current.email);
        } else {
            gs.addInfoMessage("User with this information already exists");
        }
    }

})(current, previous);

  

View solution in original post

2 REPLIES 2

Mike Patel
Tera Sage

try below (you can add value anywhere I added it to the end)

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

    var grUsr = new GlideRecord('sys_user');
    grUsr.addQuery('user_name', current.user_name).addOrCondition('email', current.email);
    grUsr.query();

    if (grUsr.next()) {
        current.setAbortAction(true);
        if (grUsr.user_name == current.user_name) {
            gs.addInfoMessage("User with this user id already exists " + current.user_name);
        } else if (grUsr.email == current.email) {
            gs.addInfoMessage("User with this email already exists " + current.email);
        } else {
            gs.addInfoMessage("User with this information already exists");
        }
    }

})(current, previous);

  

Thank you!