- 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 08:08 AM - edited 10-13-2022 08:00 PM
Hi,
I have tried as below, not sure if I am missing something
Variable name is: which_application
In the question_choice table I have to get the 'Application Name'(app_name) question and compare the variable value with the 'Value' field
Script Include:
var AppName = Class.create();
AppName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAppDetails: function(app){
var que = this.getParameter('app_name');
var gr = new GlideRecord('question_choice');
gr.addEncodedQuery('question=103d1e4bdb3d9810c69960d444961966');
gr.get(que);
var adDetails = this.newItem("result");
adDetails.setAttribute("value", gr.getValue('value'));
},
type: 'AppName'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//var app = g_form.getValue('which_application');
var getAdDetails = new GlideAjax('AppName');
getAdDetails.addParam('sysparm_name', 'getAppDetails');
getAdDetails.addParam('app_name', newValue);
getAdDetails.getXML(fetchAppDetails);
function fetchAppDetails(serverResponse) {
var result = serverResponse.responseXML.getElementByTagName("result");
var value = result[0].getAttribute('value');
if (newValue == value) {
g_form.clearValue('which_application');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 04:03 AM
Hi,
Thanks I was able to do that.
Now I have one more query related to this.
While I compare the values, If the value in the question_choice is ABC and the one entered in the variable is ABC, it is working correctly and clearing the value, but if I enter abc in the variable it is not clearing and accepting it, how do make it like case-insensitive?