- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 03:04 AM
Hi Everyone,
I just want to know whether the following thing is possible or not.
I have a choices like apple,mango,orange,banana in "fruit type" choice field and I have a string field "fruit name". When user enters value in string field, it needs to compare with choices if the value already exists in choices then a info message or alert should be populated like Fruit already exists. For example if user enters apple in string field, as Apple already there in choices the alert should be populated. If user enters pineapple, then as pineapple is not there in choices, it should be added as a choice to that choice field.
Thank you.
Rakesh
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 03:27 AM
Hi,
In this case you can write onChange client script on string field.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('checkChoiceValues');
ga.addParam('sysparm_name','getDetails');
ga.addParam('sysparm_choiceVal',newValue); //newValue will requester for
ga.getXML(callback);
function callback(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer==true||answer=='true'){
alert("choice already present");
}
}
}
Create script include
Script include name - checkChoiceValues
client callable - true
var checkChoiceValues = Class.create();
checkChoiceValues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails :function(){
var choiceVal=this.getParameter('sysparm_choiceVal');
var gr=new GlideRecord('sys_choice');
gr.addQuery('value',choiceVal);
gr.query();
if(gr.next())
{
return true;
}
else{
return false;
}
},
type: 'checkChoiceValues'
});
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 06:38 AM
Please check the below things and guide me if I did anything wrong. I have entered the "Testing center" as value in string field which is not there in choice list. But it is not added to the choice field.
Script Include:
On change Client Script:
Table:
Choice List;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 06:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 09:00 PM
It is working. Thanks a lot for your support and suggestions. Stay safe and take care.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2020 09:15 PM
Hi,
Glad it helped you.
Have great day, Stay safe and take care.
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2020 02:01 AM
Hi Dhananjay,
A small extended requirement of the above thing, Is it possible to do a keyword search of string? for example I have Tech Mahindra in Choice list and if user enters "techmahindra" or "mahindra" it needs to be show alert? How to achieve this?
Thanks.