function onSubmit() {
var arr=[];
var loc=g_form.getValue('create_new_sites');// Internal name of multiline variable set
if(loc == '[]' ){
g_form.addErrorMessage('You must enter at least 1 row');
return false;
}
var data = JSON.parse(loc);
var ct= 0;
for(var i in data){
if (data.hasOwnProperty(i)) {
arr.push(data[i].name1.toString().replace(/\s/g, "")) ; //added a ) here
}

ct=ct+1;
}


function removeDuplicate(arr) { 
var c; 
var len = arr.length; 
var result = []; 
var obj = {}; 
for (c = 0; c<len; c++) { 
obj[arr[c]] = 0; 
} 
for (c in obj) { 
result.push(c); 
} 
return result; 
} 
if(removeDuplicate(myArr).length>0){
g_form.addErrorMessage('Duplicate value present');
return false;
}
}

mark correct if this works for you

It create a record in the table. If record already present in the table, we dont want to submit the Request.

Table name is Site.

For eg:- IF A is already present in the table site and i want to create a new record with the same name A, then it throw an error that record already present in table and doesnt submit the request.

Uh oh, your requirement was not clear initially.

now you need both script include,and  glideajax to prevent creation.

using your script itself:

make sure client callable is checked

var siteDetails = Class.create();
siteDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
sitecheck: function(){
var ans= 'false';
var gr=new GlideRecord('u_cmdb_ci_sites_using');
gr.addQuery("name",this.getParameter('sysparam_id'));
gr.query();
gr.next();
if(gr.next())
{
ans='true';
}
return ans;
},
type: 'siteDetails'
});

Catalog client script(inside multiline variable set)

function onSubmit() {
var arr=[];
var loc=g_form.getValue('create_new_sites');// Internal name of multiline variable set
if(loc == '[]' ){
g_form.addErrorMessage('You must enter at least 1 row');
return false;
}
var data = JSON.parse(loc);
var ct= 0;
for(var i in data){
if (data.hasOwnProperty(i)) {
arr.push(data[i].name1.toString().replace(/\s/g, "")) ; //added a ) here
}
}

for(var j=0;j<arr.length;j++){

var ga=new GlideAjax('siteDetails');
ga.addParam('sysparm_name','sitecheck');
ga.addParam('sysparam_id',arr[j].toString());
ga.getXML(Process);
}
}

function Process(response)
{
var answer=response.responseXML.documentElement.getAttribute("answer");
if(answer=='false')
{
g_form.clearValue('name1');
alert("error");
return false;
}
}

 

 

these should work unless there are  other dependency with the namings

It give me the alert but submit the form.