Variable field duplicate check

SNOW39
Tera Expert

How can i check if the text entered in the variable which is a free field text is not repeated. Is there a table that store the value entered in variable of a catalog item.

10 REPLIES 10

we are trying to find out if we have any table that stores the value enterd and submitted by user for this variable

There are three options :

1) Use "sc_item_option" table which stores all the values for variables. In the question field(item_option_new), pass the sys_id of the variable you wanted to test.

2) Make it a record producer instead of catalog item

3) If you have any custom table that can store these values then write an onsubmit client script to store those values in that table 

Then write onChange client script on that field to validate that value.

 

Mark it as correct if it works for you.

Regards,

Sumanth

Write onChange client script on that field and script include as below

 

Client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   
	var gaj = new GlideAjax('ScriptIncludeName'); // add script inc name
	gaj.addParam('sysparm_name','funOne');
	gaj.addParam('sysparm_field',newValue);
	gaj.getXML(ajaxResponse);
	function ajaxResponse(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		
		var values = answer.split(',');
		
		if (values.indexOf(newValue) != -1)
		  {
			alert("This value already exists");
		  }
					
		
	}
   
}

 

 

Script include :

funOne : function()
	{
		var value = this.getParameter('sysparm_field');
		var answers =[];
		var gr = new GlideRecord('sc_item_option');
		gr.addQuery('item_option_new','sys id of the variable in catalog item');
		gr.query();
		while(gr.next())
			{
				answers.push(gr.value.toString());
			}
		return answers.toString();
		
		
	},

 

Mark it as correct if it works for you.

Regards,

Sumanth

Hi,

are you having catalog item or record producer for this?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

it is a catalog item and we are trying to use any existing table.