How to make UI Page field mandatory while cancelling the Change Request?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 09:03 PM - edited ‎04-24-2024 09:13 PM
I was trying to make field mandatory while cancelling the incident, but it's not working.
When user clicks on Cancel Request UI action alert should come, if user clicks on OK on the alert, then UI page should come with mandatory field. User needs to fill that field in order to cancel the Change Request.
UI Action:
var changeConfirmCancelDialog;
function setChangeCancelState() {
var answer = confirm(getMessage('Are you sure you want to cancel this Change Request?'));
if(answer == false){
return false;
}
if(answer == true){
var uiPageSysId = '83972214c3322200b6dcdfdc64d3ae3c'; // Passing UI Page sys_id here
var url = '/ui_page.do?sys_id=' + uiPageSysId;
g_navigation.open(url,'_blank');
}
if(answer == true && (current.reason.nil() == false)){
g_form.setValue("state", "4");
//g_form.setValue("u_approval","Cancelled");
gsftSubmit(null, g_form.getFormElement(), 'state_model_move_to_canceled');
}
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}
UI Page HTML:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:dialog_notes_ok_cancel
dialog_id="change_confirm_cancel"
textarea_id="change_confirm_reason_text"
textarea_label="${gs.getMessage('Reason')}"
textarea_label_title="${gs.getMessage('A reason is required to cancel this change')}"
textarea_name="change_confirm_reason_text"
textarea_onkeyup="enableButton()"
textarea_onchange="enableButton()"
textarea_style="height:auto; width: 100%; resize: vertical;"
textarea_title="${gs.getMessage('Enter the reason here')}"
ok=""
ok_action="cancelChangeRequest"
ok_id="change_confirm_ok_btn"
ok_title="${gs.getMessage('Cancel change request')}"
ok_type="button"
ok_style_class="btn btn-primary disabled"
cancel_title="${gs.getMessage('Close the dialog')}"
/>
</j:jelly>
UI Page Client Script:
function cancelChangeRequest() {
var textArea = $("change_confirm_reason_text");
if (textArea)
moveToCancel(textArea.value.trim());
}
(function() {
$("change_confirm_reason_text").focus();
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 09:19 PM
hi @Admin7267
Go through this link, It helps.
creating a mandatory field in ui page?
Make UI Page Text area mandatory
Regards,
Siddharam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 09:35 PM
Hi @Admin7267 ,
I have done a small change to your UI action script, it should work for you -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 09:46 PM
if the ask is just to enter the reason then this can be done using javascript prompt box where user can type in the reason
why to use UI page for this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader