- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2025 03:49 AM
Hi @NatrajS93604625
Field A (Password): Create a field of type Password (2 Way Encrypted)
Create a simple table (e.g., u_password_access_log) to store the audit trails.
-
Fields: User (Reference), Time (DateTime), Reason (String), Action Type (View/Edit), Related Record (Reference to your custom table).
Create a form button (UI Action) named "Unlock Password" or "View Password".-
Client Side: true
-
OnClick: askForReason()
-
Condition: gs.hasRole('password_manager')
function askForReason() { // 1. Open a Dialog (GlideModal) to ask for the Reason var dialog = new GlideModal('glide_prompt', true, 400); dialog.setTitle('Security Audit'); dialog.setPreference('title', 'Please enter a reason to access this password:'); dialog.setPreference('onPromptComplete', function(reason) { if (reason) { // 2. If reason is provided, call the server unlockField(reason); } else { g_form.addErrorMessage('Reason is mandatory to access the password.'); } }); dialog.render(); } function unlockField(reason) { var ga = new GlideAjax('PasswordSecurityHelper'); // Call Script Include ga.addParam('sysparm_name', 'logAccessAndUnlock'); ga.addParam('sysparm_reason', reason); ga.addParam('sysparm_record_id', g_form.getUniqueValue()); ga.getXMLAnswer(function(response) { var result = JSON.parse(response); if (result.success) { // 3. SUCCESS: Unlock the field for editing g_form.setReadOnly('u_password_field', false); g_form.flash('u_password_field', 'green', 0); g_form.addInfoMessage('Access granted and logged.'); // OPTIONAL: If "View" is needed, pop up the decrypted password if(result.decrypted_password) { alert("Password: " + result.decrypted_password); } } }); }Create a Client Callable Script Include (
PasswordSecurityHelper) to handle the security logging and decryption.logAccessAndUnlock: function() { var reason = this.getParameter('sysparm_reason'); var docId = this.getParameter('sysparm_record_id'); // 1. Log to your Custom Audit Table var audit = new GlideRecord('u_password_access_log'); audit.initialize(); audit.u_user = gs.getUserID(); audit.u_action_type = 'Edit Access'; // or 'View' audit.u_reason = reason; audit.u_related_record = docId; audit.insert(); // 2. Return Success // If "View" is required, you can decrypt here using: // var enc = new GlideEncrypter(); // var decrypted = enc.decrypt(gr.u_password_field); return JSON.stringify({ success: true }); }
Happy to help! If this resolved your issue, kindly mark it as the correct answer ✅ and Helpful and close the thread 🔒 so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025 -