How to check if the selected options from list collector is valid using catalog client script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2022 07:20 AM
Hi,
I have a requirement to validate the options selected from the list collector against an existing table if the table record entry already has the selected option in them then it should not allow me to submit the request. For Example: (I have already submitted a request for the application. I am Gliding through the existing table record to see if the application is already present if it is present i should not be able to submit the catalog request else it should allow me to submit the request).
Below is script:
Catalog Client Script: OnSubmit
function onSubmit() {
if (g_scratchpad.isFormValid) {
return true;
}
var appList = g_form.getValue('select_the_application_name');
alert("appList: " + appList);
var ajx = new GlideAjax('CheckAssessment');
ajx.addParam('sysparm_name', 'getApplications');
ajx.addParam('sysparm_app', g_form.getValue('select_the_application_name'));
ajx.getXMLAnswer(getNewUserDetails);
return false;
function getNewUserDetails(answer) {
if (answer != "No Application Found") {
//var answer = response.responseXML.documentElement.getAttribute("answer");
var answerArr = answer.toString().split(',');
alert("answerArr: " + answerArr + " ,answerArr.length: " + answerArr.length);
g_form.addErrorMessage('Assessment is already initiated for the application ' + answerArr);
return false;
} else {
g_form.submitted = true;
g_scratchpad.isFormValid = true;
g_form.submit(g_form.getActionName());
return true;
}
}
}
Script Include:
var CheckAssessment = Class.create();
CheckAssessment.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getApplications: function() {
gs.info("Assessment - Inside Script Include");
var assmtTaken = [];
var getApplicationSysId = this.getParameter('sysparm_app');
gs.info("Assessment - getApplicationSysId: " + getApplicationSysId);
getApplicationSysId = getApplicationSysId.toString().split(',');
gs.info("Assessment - getApplicationSysId.length: " + getApplicationSysId.length);
for (var i = 0; i < getApplicationSysId.length; i++) {
var applicationName;
gs.info("Assessment - getApplicationSysId: " + getApplicationSysId[i] + " ,i value is: " + i);
var appName = new GlideRecord("cmdb_ci_business_app");
appName.addQuery("sys_id", getApplicationSysId[i]);
appName.query();
if (appName.next()) {
applicationName = appName.getValue("name");
gs.info("Assessment - applicationName: " + applicationName);
}
var queryVal = "metric=3rtgefab1b8f55143452da02b24bcb48^category=b55c2dgfdrtf55143771da02b24bcb90^string_value=" + applicationName;
var app = new GlideRecord("asmt_assessment_instance_question");
app.addEncodedQuery(queryVal);
app.query();
if (app.next()) {
gs.info("Assessment - applicationName Found");
assmtTaken.push(applicationName);
}
}
if(assmtTaken.length > 0){
return assmtTaken.toString();
}else{
return "No Application Found";
}
},
type: 'CheckAssessment'
});
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2022 08:59 AM
Duplicate post...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!