- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2023 11:38 PM - edited 12-10-2023 11:39 PM
Hi team ,
I need to hide field text based on role or group ,
For example : incident form have description filed, so based on role I will set encrypt or decrypt
Can any one provide me solution for this how to achieve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 05:36 AM
Hello @Gillerla Rajesh
As per your recent feedback you can refer the below OnLoad client script.
function onLoad() {
// Check if the user has the specified role
var hasRole = g_user.hasRole('admin');
// Get the reference to the field
var field = g_form.getControl('description');
// Check if the user has the role and set the display accordingly
if (hasRole) {
// If the user has the role, show the decrypted value
field.type = 'text'; // Use 'text' type to display the decrypted value
} else {
// If the user doesn't have the role, show the encrypted value
field.type = 'password'; // Use 'password' type to display the encrypted value
}
}
Please mark my answer as helpful and the solution accepted if it serves the purpose.
Regards,
Aniket.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 07:28 AM
Hello @Gillerla Rajesh ,
Yes I know the difference between encrypt and decrypt and as per my understanding only I have answered to your requirement,
Like you want to show field value is encrypted or decrypted based on the users role and this decrypted value means not the actual decrypt word you want to show it like it happens with password field with dot or star
So according to that only I have provided you the on load client script which will check the role and based on that it will mask the field valu if needed.
Correct me if I misunderstood anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 04:11 AM
Hello @Gillerla Rajesh ,
No worries at all and you can refer to the code below in which I just have added group condition with the help of display business rule and client script, so either group or role will be required.
Display Business Rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.grp = gs.getUser().isMemberOf('TM.ServiceNow');
})(current, previous);
On Change Client Script:
function onLoad() {
// Check if the user has the specified role
var hasRole = g_user.hasRole('admin');
// Check if the user is a member of the specified group
// g_scratchpad.grp will be true if the user is a member
var isMemberOfGroup = g_scratchpad.grp === true;
// Get the reference to the field
var field = g_form.getControl('short_description');
// Check if the user has the role or is a member of the group and set the display accordingly
if (hasRole || isMemberOfGroup) {
g_form.addInfoMessage("inside if");
// If the user has the role or is a member of the group, show the decrypted value
field.type = 'text'; // Use 'text' type to display the decrypted value
} else {
g_form.addInfoMessage("inside else");
// If the user doesn't have the role or is not a member of the group, show the encrypted value
field.type = 'password'; // Use 'password' type to display the encrypted value
}
}
Please let me know if you still face any issues.
Mark ✅Correct if this solves your issue and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 05:36 AM
Hello @Gillerla Rajesh
As per your recent feedback you can refer the below OnLoad client script.
function onLoad() {
// Check if the user has the specified role
var hasRole = g_user.hasRole('admin');
// Get the reference to the field
var field = g_form.getControl('description');
// Check if the user has the role and set the display accordingly
if (hasRole) {
// If the user has the role, show the decrypted value
field.type = 'text'; // Use 'text' type to display the decrypted value
} else {
// If the user doesn't have the role, show the encrypted value
field.type = 'password'; // Use 'password' type to display the encrypted value
}
}
Please mark my answer as helpful and the solution accepted if it serves the purpose.
Regards,
Aniket.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 05:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 07:28 AM
Hello @Gillerla Rajesh ,
Yes I know the difference between encrypt and decrypt and as per my understanding only I have answered to your requirement,
Like you want to show field value is encrypted or decrypted based on the users role and this decrypted value means not the actual decrypt word you want to show it like it happens with password field with dot or star
So according to that only I have provided you the on load client script which will check the role and based on that it will mask the field valu if needed.
Correct me if I misunderstood anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 07:52 AM
Thanks for ur reply, I need like this the pic i am attached like that way format, based on role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 07:55 AM
Try these links
https://www.servicenow.com/community/itsm-forum/how-to-decrypt-user-password/m-p/561097
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************