File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
Server-Side Components/Business Rules/AbortChangeRequest Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ #BusinessRule
2+ ( function executeRule ( current , previous /*null when async*/ ) {
3+
4+ // Add your code here
5+ var user = current . requested_by ;
6+ var obj = new withClass3 ( ) ;
7+ var res = obj . getCount ( user ) ;
8+ if ( res > 5 ) {
9+ gs . addErrorMessage ( "You have already made change requests more than 5 times" ) ;
10+ current . setAbortAction ( true ) ;
11+ }
12+
13+ } ) ( current , previous ) ;
14+ #ScriptInclude
15+
16+
17+ var withClass3 = Class . create ( ) ;
18+ withClass3 . prototype = {
19+ initialize : function ( ) {
20+ } ,
21+
22+ getCount : function ( user ) {
23+ var gr = new GlideRecord ( 'change_request' ) ;
24+ gr . addQuery ( 'requested_by' , user ) ;
25+ gr . query ( ) ;
26+ return gr . getRowCount ( ) ;
27+
28+ } ,
29+
30+ type : 'withClass3'
Original file line number Diff line number Diff line change 1+ # Change Request Limit (ServiceNow)
2+
3+ ## Overview
4+ This customization prevents users from creating more than ** 5 Change Requests** in ServiceNow.
5+
6+ If a user has already created 5 or more requests, the system shows an error and stops the record from being submitted.
7+
8+ # How It Works
9+
10+ 1 . User creates a Change Request.
11+
12+ 2 . Script Include counts how many CRs they already have.
13+
14+ 3 . If count > 5 → Show error → Stop record creation.
You can’t perform that action at this time.
0 commit comments