Variable field duplicate check
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 02:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 04:05 AM
we are trying to find out if we have any table that stores the value enterd and submitted by user for this variable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 05:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 03:51 AM
Hi,
are you having catalog item or record producer for this?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 04:07 AM
it is a catalog item and we are trying to use any existing table.