Gliderecord not working in catalog client scripts

Jake Adams
Tera Contributor

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');
}

}

 

1 ACCEPTED SOLUTION

@Jake Adams 

 

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');

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

6 REPLIES 6

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

 

JakeAdams_0-1665673590843.png

 

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');
}

}
}

 

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?