Glide Model in form

Mohan Mallapu
Kilo Sage

Hi All,

Much appreciated if anyone help me with below requirement. 


We already known the set password(Generate and save password) functionality from sys_user record. 
My Requirement:
i have created custom UI page( copied the code from OOTB glidemodel:generate_copy_password)  for  my custom application here i want to extend the functionality of this glidemodel.

MohanMallapu_0-1676995114417.png

 


Here want to add the some more fields to this glide model: schedule password Check box, Once check box is selected, another field : Scheduled date (date field) should be shown and User need to select the date to schedule password.  Once they selected the schedule password,  Need to enable the another button called Reschedule password with close and save password buttons.

 

If user selected the check box true and mention the scheduled date clicked on the Reschedule password button then the glide model need to disable and the details should be saved in the form fields from glide model.

 

Jelly Script:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
input::-ms-reveal,
input::-ms-clear {
display: none;
}

#divNotification {
margin-block-end: var(--now-global-space--sm, 8px);
}
</style>
<g2:evaluate var="jvar_password_field_disabled" jelly="true">
var password_field_disabled = gs.getProperty('glide.password.policy.generate.password.field.disabled',true);
password_field_disabled;
</g2:evaluate>

<div class="notification notification-success" id="divNotification" style="display:none;">
<button data-dismiss="alert" class="btn-icon close icon-cross">
<span class="sr-only">${gs.getMessage('Close')}</span>
</button>
</div>

<div style="text-align:left;">
<div class="form-inline flex">
<div class="form-group">
<p id="btnDescription" class="sr-only" aria-live="polite">${gs.getMessage('Password hidden')}</p>
<div class="input-group password-group">
<input id="password" type="password" class="form-control" style="width:30rem" aria-label="${gs.getMessage('password')}" autocomplete="new-password" value="" placeholder="${gs.getMessage('Password')}"></input>
<span class="input-group-btn">
<button
id="mask_icon"
type="button"
class="btn btn-default icon-preview input-group-append mask_btn sn-tooltip-basic"
onClick="renderMaskIcon(this)"
aria-label="${gs.getMessage('Show Password')}"
data-original-title="${gs.getMessage('Show password')}"
data-toggle="tooltip" />
<button
id="copy_code"
aria-label="Click to copy code"
data-original-title="Click to copy password"
data-toggle="tooltip"
class="btn btn-default sn-tooltip-basic icon icon-copy"
title=""
onclick="copyPassword(this)" />
</span>
</div>
<button id="generate" class="btn btn-secondary" style="margin-left:10px" onclick="generatePassword()">${gs.getMessage('Generate')}</button>
</div>
</div>
</div>

<div align="right" class="modal-footer">
<g:dialog_buttons_ok_cancel ok="return setPassword()" ok_id="set_password" ok_text="${gs.getMessage('Save Password')}" cancel="return cancel(this)" ok_type="button" cancel_type="button" cancel_text="${gs.getMessage('Close')}"/>
</div>
<script>
document.getElementById("generate").focus();
</script>
</j:jelly>

client Script: 

 

var passwordFieldDisabled = $[jvar_password_field_disabled];
document.getElementById("set_password").disabled = true;
document.getElementById("password").disabled = passwordFieldDisabled;

function generatePassword() {
var userName = GlideModal.get().getPreference('sysparm_user');
if (!userName)
showMessage(new GwtMessage().getMessage("Not a valid user."), "error");

var ga = new GlideAjax('PasswordPolicyUtil');
ga.addParam('sysparm_name', 'generatePassword');
ga.addParam('sysparm_user', userName);
ga.getXMLWait();
var password = ga.getAnswer();
if (password == 'false' || password == "") {
showMessage(new GwtMessage().getMessage("password generation failed."), "error");
} else {
document.getElementById("password").value = password;
showMessage(new GwtMessage().getMessage("Password generated succesfully."), "info");
document.getElementById("set_password").disabled = false;
}
}

function setPassword() {
//Set up the user password with the password present in the input field
var userName = GlideModal.get().getPreference('sysparm_user');
var password = document.getElementById("password").value;
var ga = new GlideAjax('PasswordPolicyUtil');
ga.addParam('sysparm_name', 'setPassword');
ga.addParam('sysparm_user', userName); //Parm1
ga.addParam('sysparm_password', password); //Parm2
ga.getXML(this.processResponse.bind(this));
return false;
}

function processResponse(response) {
var outputs = response.responseXML.getElementsByTagName("output");
if (outputs && outputs.length > 0) {
var success = outputs[0].getAttribute("success");
var msg = outputs[0].getAttribute("message");
if (success == "false") {
showMessage(msg, "error");
} else {
showMessage(msg, "info");
}
return;
}
}

function showMessage(msg, type) {
var notificationContainer = gel("divNotification");
if (type == 'info')
notificationContainer.setAttribute("class", "notification notification-success");
else if (type == 'error')
notificationContainer.setAttribute("class", "notification notification-error");
notificationContainer.style.display = "block";
notificationContainer.innerText = msg;
}


function copyPassword(curr) {
var password = document.getElementById("password").value;
if (!password)
showMessage(new GwtMessage().getMessage("Password is empty."), "error");
else
copy(password);
}

function copy(text) {
var elem = document.createElement('textarea');
elem.value = text;
document.body.appendChild(elem);
elem.select();
document.execCommand('copy');
document.body.removeChild(elem);
showMessage(new GwtMessage().getMessage("Password copied successfully."), "info");
}

$('password').observe('keyup',
function() {
var password = document.getElementById("password").value;
if (password) {
document.getElementById("set_password").disabled = false;
} else {
document.getElementById("set_password").disabled = true;
}
});

function renderMaskIcon(element) {
var passwordEle = document.getElementById("password");
var maskEle = document.getElementById("mask_icon");
var btnDescription = document.getElementById("btnDescription");
var isPasswordType = passwordEle.type === 'password';
maskEle.classList.toggle('active', isPasswordType);
maskEle.setAttribute("data-original-title", (isPasswordType) ? "${gs.getMessage('Hide password')}" : "${gs.getMessage('Show password')}");
element.setAttribute("aria-label", (isPasswordType) ? "${gs.getMessage('Hide password')}" : "${gs.getMessage('Show password')}");
passwordEle.type = (isPasswordType) ? 'text' : 'password';
btnDescription.textContent = (isPasswordType) ? "${gs.getMessage('Password shown')}" : "${gs.getMessage('Password hidden')}";
}

document.addEventListener('click', function(e) {
if (e.target.matches('[data-dismiss="GlideModal"]')) {
location.reload();
}
});

0 REPLIES 0