Skip to content

Commit f04f292

Browse files
authored
Add CI validation via GlideAjax
This script validates a Configuration Item (CI) selection via GlideAjax, checking if the CI is operational and has an assignment group.
1 parent 3654c47 commit f04f292

File tree

1 file changed

+37
-0
lines changed
  • Client-Side Components/Catalog Client Script/Validate CI selection via GlideAjax with submit guard

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var CIValidationAjax = Class.create();
2+
CIValidationAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
validateCi: function() {
4+
var ciSysId = this.getParameter('sysparm_ci');
5+
var result = { valid: false, display: '', message: '' };
6+
7+
if (!ciSysId) {
8+
result.message = 'No CI provided.';
9+
return JSON.stringify(result);
10+
}
11+
12+
var ci = new GlideRecord('cmdb_ci');
13+
if (!ci.get(ciSysId)) {
14+
result.message = 'CI not found.';
15+
return JSON.stringify(result);
16+
}
17+
18+
result.display = ci.getDisplayValue();
19+
20+
// Example rules: CI must be operational and have an assignment group
21+
var isOperational = String(ci.install_status) === '1'; // installed
22+
var hasGroup = !!ci.assignment_group;
23+
24+
if (isOperational && hasGroup) {
25+
result.valid = true;
26+
return JSON.stringify(result);
27+
}
28+
29+
var reasons = [];
30+
if (!isOperational) reasons.push('CI is not operational');
31+
if (!hasGroup) reasons.push('no assignment group is set');
32+
result.message = 'CI is not valid: ' + reasons.join('; ') + '.';
33+
return JSON.stringify(result);
34+
},
35+
36+
isPublic: function() { return true; }
37+
});

0 commit comments

Comments
 (0)