File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Client-Side Components/Catalog Client Script/Validate CI selection via GlideAjax with submit guard Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments