- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 07:12 AM
In Change Request form how to make service offering field mandatory When a user selects a Service in the "Service" field that belong to Business Service or Technical Service CI class
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 08:13 AM
Make sure you added the table first in UI policy
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2025 12:00 AM
so the issue is, when i am selecting technical service in "Service" field then after submitting the Change record the "Service offering" field getting mandatory automatically later on i realized to change Service in "Service" field as Non Technical or Business service and then update the change record then its not allowing me since Service offering is mandatory,
so can we have a solution for this where Service offering gets optional once we select no Technical or Business service?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2025 07:37 AM
Once again, the client script and script include I've posted below works for your use case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2025 06:13 AM - edited ‎06-09-2025 10:08 AM
What works for me is a Client Script and Script Include:
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (oldValue == newValue) {
return;
}
// make mandatory
var srvc = g_form.getValue('business_service');
var ga = new GlideAjax('CheckService');
ga.addParam('sysparm_name', 'checkServiceClass');
ga.addParam('sysparm_srvc_id', srvc);
ga.getXMLAnswer(getResponse);
// callback function for returning the result from the script include
function getResponse(response) {
var srvc = response;
if (srvc == 'true') {
g_form.setMandatory('service_offering', true);
}
// in case the service changed to one where the service_offering is not mandatory
else {
g_form.setMandatory('service_offering', false);
}
}
}Script include:
Script:
var CheckService = Class.create();
CheckService.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkServiceClass: function() {
var srvcID = this.getParameter("sysparm_srvc_id");
var retValue = false;
var srvc = new GlideRecord('cmdb_ci_service');
srvc.addQuery('sys_id', srvcID);
srvc.query();
if (srvc.next()) {
if ((srvc.sys_class_name == 'cmdb_ci_service_business') ||
(srvc.sys_class_name == 'cmdb_ci_technical_service') {
retValue = true;
}
}
return retValue;
},
type: 'CheckService'
});
Or...
a business rule can be used, but may not be the best user experience:
script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var srvcID = current.business_service;
var srvc = new GlideRecord('cmdb_ci_service');
srvc.addQuery('sys_id', srvcID);
srvc.query();
if (srvc.next()) {
if ((srvc.sys_class_name == 'cmdb_ci_service_business') || (srvc.sys_class_name == 'cmdb_ci_technical_service')) {
gs.addErrorMessage('Must supply a Service Offering for the selected Service!');
current.setAbortAction(true);
}
}
})(current, previous);
