Skip to content

Commit 3a329a2

Browse files
Merge pull request #7 from NavyasreeBolleboyana/Patch-21
AbortChangeRequest
2 parents e59b3d6 + 7675f4b commit 3a329a2

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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.

0 commit comments

Comments
 (0)