I've been working on a catalogue item that gets the values of it's variables from fields in a table.
One issue that I've noticed is that if a field from a table is a boolean and is left unchecked, ServiceNow assumes that this is set to False and it makes the fields on the catalogue item set to No, Even though I've set the unwanted field to hide, it still gets populated, leaving unwanted fields to appear.
However, this is incorrect because the details might not have been filled in properly by a user. What I'm wanting it to do is check that if the previous field had been populated. If the previous field has been populated, set it to No, otherwise, set it to Null.
My client script is:
// Otherwise we call GlideAjax and do the population
var ajaxDomain = new GlideAjax("LBGAMABusinessAssessmentCatItem");
ajaxDomain.addParam("sysparm_name", "getWholeApplication");
ajaxDomain.addParam("sysparm_sysid", newValue);
ajaxDomain.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
var jsonRet = JSON.parse(answer);
// Easy bit - set field values
//Business Application field
setValNulls("ama_category", jsonRet.u_access_management_controls);
setValNulls("legacy_or_new", jsonRet.legacy_or_new);
//AMA fields
setValNulls("u_access_fully_controlled_by_it_lbg", jsonRet.u_access_fully_controlled_by_it_lbg);
setValNulls("u_manual_order_process_met", jsonRet.u_manual_order_process_met);
setValNulls("u_mom_remediation_plan", jsonRet.u_mom_remediation_plan);
setValNulls("u_mom_remediation_plan_due_date", jsonRet.u_mom_remediation_plan_due_date);
setValNulls("u_mom_remediation_action_s", jsonRet.u_mom_remediation_action_s);
setValNulls("u_mom_risk_accepted_until", jsonRet.u_mom_risk_accepted_until);
setValNulls("u_mom_security_non_compliance_risk_detail", jsonRet.u_mom_security_non_compliance_risk_detail);
}
});
}
My Script Include is:
var LBGAMABusinessAssessmentCatItem = Class.create();
LBGAMABusinessAssessmentCatItem.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
type: 'LBGAMABusinessAssessmentCatItem',
getWholeApplication: function() {
// Retrieve parameters
var sysid = this.getParameter("sysparm_sysid");
// Outer JSON
var jsonRet = {};
// Look up the status
var grApp = new GlideRecord("cmdb_ci_business_app");
grApp.get(sysid);
//Business Application fields
jsonRet["u_access_management_controls"] = grApp.getDisplayValue("u_access_management_controls");
jsonRet["sys_created_on"] = grApp.getDisplayValue("sys_created_on");
jsonRet["number"] = grApp.getValue("number");
jsonRet["legacy_or_new"] = this.getDatePropertyDiff(grApp.getDisplayValue("sys_created_on"));
//AMA fields
var grAMA = new GlideRecord('u_uam_ama');
grAMA.get('u_business_application', sysid);
jsonRet["u_access_fully_controlled_by_it_lbg"] = grAMA.getValue("u_access_fully_controlled_by_it_lbg");
jsonRet["u_manual_order_process_met"] = grAMA.getDisplayValue("u_manual_order_process_met");
jsonRet["u_mom_remediation_plan"] = grAMA.getDisplayValue("u_mom_remediation_plan");
jsonRet["u_mom_remediation_plan_due_date"] = grAMA.getDisplayValue("u_mom_remediation_plan_due_date");
jsonRet["u_mom_remediation_action_s"] = grAMA.getDisplayValue("u_mom_remediation_action_s");
jsonRet["u_mom_risk_accepted_until"] = grAMA.getDisplayValue("u_mom_risk_accepted_until");
jsonRet["u_mom_security_non_compliance_risk_detail"] = grAMA.getDisplayValue("u_mom_security_non_compliance_risk_detail");
jsonRet["u_automated_mal_through_oim"] = grAMA.getDisplayValue("u_automated_mal_through_oim");
// Return it
return JSON.stringify(jsonRet);
},
Currently happening:

What should happen:
