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

Sharique Azim
Kilo Sage

Hi,

This cannot be done through onchange script but can be done using onsubmit script.

 

Example script:

function onSubmit() {
	var arr=[];
	var loc=g_form.getValue('name_of_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].<field_name>.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;
	}

}

 

Warning:

This is a just  an example script written on the go,please test it before deploying.

Where can i write this? 

In the multiline variable set client script or catalog item client script?

on the catalog item client script

While saving the catalog item client script, it give me an error

Line no :-23  arr.push(data[i].name1.toString().replace(/\s/g, "") ;

Could not save record because of a compile error: JavaScript parse error at line (23) column (57) problem = missing ) after argument list (<refname>; line 23)
 
 
and we have a table named site using, in that site using table Name value stored, if the name value is already present in the table then it give me an error.
 
In your code, where you compare the entered value wiith the already present value in the site using table?