throw error if value already present in table

Evan2
Kilo Guru

Hi Team, 

On Portal we have populate the value Name and the value of name is stored in "site using" table.

Requirement is to check if value of name already present in site using table, throw an error and RITM not created.

We can add multiple value by clicking on add and need to check all the values.

Note:- This all variables came  under multi line variable set

 
Ve
19 REPLIES 19

like i said i gave a sample code, obviously typos were expected.

share your full code for me to look upon

 also that i made some edit to the original ,please note

Full code:-


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, "") ;
}

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;
}
}

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.