- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2017 09:30 AM
Hi. I'm trying to hide a form section on the user table unless the user has a role or the it's the users record. I've got the first part working with the following Client Script but I don't know how to configure it so the user can see the record if it's theirs. Can anyone else?
function onLoad() {
if (g_user.hasRole('secret_qa_viewer')) {
g_form.setSectionDisplay('security_questions', true);
}
else{
g_form.setSectionDisplay('security_questions', false);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2017 04:41 AM
Okay, I managed to get it working! Here's the code:
function onLoad() {
var id = (g_form.getUniqueValue());
if (g_user.userID == id || g_user.hasRole('secret_qa_viewer')) {
g_form.setSectionDisplay('security_questions', true);
}
else{
g_form.setSectionDisplay('security_questions', false);
}
}
Thanks everyone who replied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2017 04:03 AM
Thanks but this doesn't work I'm afraid. Are you sure the user.sys_id bit is correct? I can't find any other example of it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2017 09:51 AM
Hi Wayne,
A few tip here, although the requirement is not clearly understood.
if( g_user.hasRoles() ){
can simply check if the user has ANY role (as per your words in the question)
}
you can use hasRoleFromList instead. http://wiki.servicenow.com/index.php?title=GlideUser_(g_user)#gsc.tab=0
But,please clarify on what basis are you filtering that "the ticket is of the user's" ? are you using assigned to for checking?
you can simply use
var usr= g_form.getValue('assigned_to');
if( g_user.hasRoleFromList('role') || g_form.userID==usr ){
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2017 04:10 AM
Hi sharique, thanks for the reply. I should have said "unless the user has a specific role", namely the 'secret_qa_viewer' role. This bit is working just fine, it's the latter part I can't get to work, namely when the user is viewing their own record. I'll explain it as clearly as I can.
I am the user Wayne Richmond. I have no roles, I am just an ess user. I open my own user record. I want to be able to see the section 'Secret Questions' because it's my record. I don't want anyone else to see this unless they have the security role 'secret_qa_viewer'.
I assumed I could achieve this by something like what sachin.namjoshi provided (where the current user's sys_id matches the current record's sys_id):
if (g_user.userID == user.sys_id) {
g_form.setSectionDisplay('security_questions', true);
}
Unfortunately it doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2017 04:41 AM
Okay, I managed to get it working! Here's the code:
function onLoad() {
var id = (g_form.getUniqueValue());
if (g_user.userID == id || g_user.hasRole('secret_qa_viewer')) {
g_form.setSectionDisplay('security_questions', true);
}
else{
g_form.setSectionDisplay('security_questions', false);
}
}
Thanks everyone who replied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2017 04:51 AM
Ahh, i absolutely missed that you are using the user table here. My bad.