Skip to content

Commit 524e423

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents 553c5fe + 5b5b422 commit 524e423

File tree

19 files changed

+298
-12
lines changed

19 files changed

+298
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
if(current.table_name=="incident") {
3+
4+
var attached = new GlideRecord('sys_attachment');
5+
attached.addQuery('table_name','incident');
6+
attached.addQuery('table_sys_id', current.table_sys_id);
7+
attached.addQuery('file_name',current.file_name);
8+
attached.query();
9+
if(attached.next())
10+
{
11+
12+
gs.addInfoMessage('Attachement already Exists with the Same Name do not upload same attachement');
13+
current.setAbortAction(true);
14+
15+
}
16+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Type: Business Rule When: OnBefore and On Insert Operation Table:Incident
2+
This BR runs on Insert Operation , IT compares the filename from Sysattachment table and if same attachment with Same file exists on the Incident this BR runs and Abort the Attaching Attachments
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Opens a Story attached to a Incident record in the parent field in the readonly mode.
2+
function onLoad(g_form) {
3+
g_aw.openRecord('rm_story', g_form.getValue('parent'), {readOnlyForm: true});
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This code helps to open a record in readonly mode irrespective of ACLS, UI Policies via client script in a Agent workspace tab.
2+
3+
Here we are opening a story that is stored in the parent field on the incident record in the agent workspace.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//Create a Display Business Rule with the following code and then the following code on "On-Load" client script
2+
3+
//Display Business Rule Code:
4+
/*****
5+
g_scratchpad.grpmember = gs.getUser().isMemberOf(current.assignment_group); //This returns true or false . If user is part of the group it returns true, if user is not part of the group it returns false and assign it to scratchpad variable.
6+
*****/
7+
8+
if(g_scratchpad.grpmember == false)
9+
{
10+
g_form.setReadonly("state", true);
11+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This code will make state field editable only for group members, with the help of scratchpad variable that returns true or false from display business rule.
2+
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
(function getUserRoles() {
2-
// sample user
3-
var userName = 'bow.ruggeri';
1+
function getUserRoles(userName) {
42

5-
var roleQuery = new GlideQuery('sys_user_has_role')
6-
.where('user.user_name', 'bow.ruggeri')
7-
.select(['role$DISPLAY', 'role.active', 'user$DISPLAY', 'user.email'])
8-
.toArray(100);
3+
var gqRoles = new global.GlideQuery('sys_user_has_role')
4+
.where('user.user_name', userName)
5+
.select('role$DISPLAY')
6+
// use .reduce() instead of .toArray() as it allows us to strip out only whats needed, and doesn't need to know the number of entries.
7+
.reduce(function (arr, e) {
8+
arr.push(e.role$DISPLAY);
9+
return arr;
10+
}, []);
911

10-
gs.log(JSON.stringify(roleQuery, null, 2));
11-
})();
12+
return gqRoles;
13+
};
14+
15+
gs.info(getUserRoles('bow.ruggeri'));

GlideQuery/Get User's Roles from User Name/readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
GlideQuery's can greatly simplify extracting information from queries, especially when dot walking.
44

5-
This query retrieves a user's roles, and returns an array of objects with the the role's display
6-
value, the role's active status, the user's display value, and the user's email. Adding more
7-
fields is trivial with this format, and the query stream is very easy to follow.
5+
This code has been updated to simplify the function to return an array of roles for the given user. Shows the use of GlideQuery and .reduce() in place of .toArray().
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var now_GR = new GlideRecord('incident');
2+
now_GR.get('99ebb4156fa831005be8883e6b3ee4b9');
3+
now_GR.setValue('short_description', 'Update the short description');
4+
now_GR.update("updated from BR" ); // This comment gets added to the activity log of incident for audit purposes.

0 commit comments

Comments
 (0)