I want a pop up alert if account create with simillar name?

Deepika61
Tera Contributor

Hi All,

 

Actually i have a requirement that i have Account form, on that name field with string field, so whenever user will create new record if he type similar name which already exist . example  Asian Paints is one account,

1.so if he wants create with same name then it won't submit a record 

2. second senario was " Asian paints" , if he type something simillar like Asian or Paints , then it pop up a alert message saying " already a record exist similar name , do you want proceed?, if he click ok it save otherwise , will update new name

 

Please help me to achieve this

Thanks

Deepika

11 REPLIES 11

Hi @Deepika61 

 

I can understand your point but we need to see other side, 

Lets say 

there are 2 accounts name

 

Asian

Asians

 

Now it look similar but you are adding validation. Instead of this, add a new field like account id and it can be combine of Name _ other parameters.

 

As suggested by @Sumanth16 name can be similar.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Sumanth16
Kilo Patron

Hi @Deepika61 ,

 

Using an on change client script and must make a GlideAjax call to a script include and return the information you desire.

 

For this example, the below would work:

Catalog Client Script:

 

function onChange(control, oldValue, newValue, isLoading) {

   if (isLoading || newValue == '') {

      return;

   }

   //Type appropriate comment here, and begin script below

var ga = new GlideAjax('getgroupinfo');

ga.addParam('sysparm_name','groupname');

ga.addParam('sysparm_group',newValue);

ga.getXMLAnswer(dosomething);

function dosomething(response){

var answer = response;

if (answer){

alert('Group name already exists');

}

} 

}

Script Include: (Ensure Client Callable):

var getgroupinfo = Class.create();

getgroupinfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

   groupname: function() {

var userGR = new GlideRecord('sys_user_group');

if (userGR.get('name', this.getParameter('sysparm_group'))){

return true;

}

},

 

    type: 'getgroupinfo'

});

 

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,
Sumanth Meda

@Sumanth16 

Thanks for the code 

first thing in my case table is Account and field is " name' which is string field

second thing i want a confirm box with ok and cancel , when name contains similar name like as i said above suppose "Assian paints " one record name, so now if new record name is create with like Assian , then need a confirm message do you want to continue ?

can you please tell me  where should i make changes in your code for that ?

 

Thanks

Deepika

 

 

Service_RNow
Mega Sage

Hi @Deepika61 

Try to with BR only then do with before insert 

Sample logic:

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

    var grP = new GlideRecord("table_name");
    grP.addQuery("field_name", current.getValue("field_name"));
    grP.addQuery("field_name", current.getValue("field_name"));
grP.setLimit(1);
    grP.query();
    if (grP.hasNext()) {
       gs.addErrorMessage("This is a duplicate record");
        current.setAbortAction(true);
    }

})(current, previous);

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

Amit Gujarathi
Giga Sage
Giga Sage

HI @Deepika61 ,
I trust you are doing reat.
You can create script include and call in the onsubmit client script as given below :
Script include:

// NameValidationAjax.js

var NameValidationAjax = Class.create();

NameValidationAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkNameExists: function() {
        var name = this.getParameter('sysparm_name_input');
        var gr = new GlideRecord('account_table_name'); // Replace 'account_table_name' with your actual table name
        gr.addQuery('name', name);
        gr.query();
        return gr.hasNext() ? 'true' : 'false';
    }
});

Client Script :

// NameValidationClientScript.js

function onSubmit() {
    var name = g_form.getValue('name'); // Assuming 'name' is the field name

    // Query the table to check if the name already exists
    var ga = new GlideAjax('NameValidationAjax');
    ga.addParam('sysparm_name', 'checkNameExists');
    ga.addParam('sysparm_name_input', name);
    ga.getXMLAnswer(function(response) {
        if (response == 'true') {
            alert('A record with the same name already exists. Please choose a different name.');
            return false; // Prevent submission
        }
    });
    return true; // Allow submission if name doesn't exist
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi