- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 03:41 AM
Hi,
I have a single line text variable in a catalog. The variable question is 'which application'
In the question_choice table for the question 'which application' I have added 4 choices A, B, C and D.
Now when I enter a value in the single line text and that value matches anyone of this choice. I want to clear the single line field.
I am trying to write a onChange client script but it's not working
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//var ad = g_form.getValue('which_application');
var gr = new GlideRecord('question_choice');
gr.addEncodedQuery('question=103d1e4bdb3d9810c69960d444961966');
gr.query();
while (gr.next()) {
if (gr.value == g_form.getValue('which_application')) {
g_form.clearValue('which_application');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 06:01 AM
In that case you have to use Script Include using GlideAjax() API where you can pass your 'which_application' value. In that Script Include you can query 'question_choice' table using GlideRecord and compare values and return true if both are same.
Then in your Catalog Client script you can check that if answer is true than g_form.clearValue('which_application');
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 03:50 AM
It is a bad practice to use GlideRecord in a client script. Use GlideAjax. Use below article on how to use GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 04:12 AM
As you mentioned you have 1 variable only as single Line Text and also have there Choices defined, I guess you will get only those 4 choices and not text field to put any value.
Can you show the screenshot of your variable, how it looks?
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 05:22 AM
Hi,
Yes it's a single line text but the he choices I have added are not showing up in it.
The thing is I don't want to allow that 4 values to be entered in that text variable.
I was using index of but my client was not satisfied with that, and want to store those values in question_choice table and query it and based on it need to restrict those values.
Is there any other best way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 06:01 AM
In that case you have to use Script Include using GlideAjax() API where you can pass your 'which_application' value. In that Script Include you can query 'question_choice' table using GlideRecord and compare values and return true if both are same.
Then in your Catalog Client script you can check that if answer is true than g_form.clearValue('which_application');
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023