Custom Ui action not working when impersonated with non-admin account
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 12:37 AM
Requirement:
By impersonating a user with the BCM Program Manager (sn_bcm.program_manager) or BCM Admin (sn_bcm.admin) role, the user is able to view a "Cancel" UI action in all BIA (sn_bia_analysis) records.
If the "Cancel" UI action is clicked, a modal window will appear that will require the user to provide justification via comments, then the record should move to the "Closed Incomplete" state.
Ui action code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 02:23 AM
@Nikhitha Gandhi
Could you please check the logs on syslog table and share if there any errors thrown?
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 01:30 AM
when non-admin clicks the modal opens but nothing happens when they click submit?
share the UI page code here
was this working fine earlier?
Is that UI page and UI action an OOB ones?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 01:39 AM
Yes, when non-admin clicks the modal opens but nothing happens when they click submit.
The UI page and Ui action are custom ones.
HTML code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 02:27 AM
is it going till this line? see alert I added
1) state and comments are present in the form view in which user is clicking the UI action
2) those 2 fields are editable when button is clicked
function handleSubmit() {
var modal = GlideModal.get();
var actionName = modal.getPreference('methodName');
var commentsElement = gel("comments");
var comments = commentsElement.value;
comments = trim(comments);
if (comments != '') {
alert('this came');
g_form.setValue('state', 4);
g_form.setValue('comments', comments);
g_form.save();
}
Another way -> Pass the record sysId from UI action and use GlideRecord to update
UI Action:
function cancelBia() {
var modal = new GlideModal("sn_bia_ABT:Cancel_Bia", false, 500);
modal.setTitle(getMessage("Request additional information"));
modal.setPreference('methodName', "cancel_bia_analysis");
modal.setPreference('sysId', g_form.getUniqueValue());
modal.setBackdropStatic(true);
modal.render();
}
if (typeof window == 'undefined')
updateTask();
function updateTask() {
current.update();
action.setRedirectURL(current);
}
Then get it in HTML and then use that in client script
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:evaluate var="jvar_sysId" expression="RP.getWindowProperties().sysId"/>
<input type="hidden" id="recordsysid" value="${jvar_sysId}"/>
<style>
#report_risk .required-marker{
display: inline-block;
}
.request-textarea {
resize: vertical;
}
.modal-error{
background-color: #ffdadc;
border-color: #c83c36 transparent;
border: solid 1px;
border-radius: 3px;
color: #64201a;
padding: 10px;
margin-top: 6px;
margin-bottom: 0px;
display:none;
}
</style>
<div class="row">
<div class="form-horizontal">
<div class="form-group">
<label id="comments_label" class="col-sm-3 col-sm-offset-1 control-label">${gs.getMessage('Comments')}</label>
<div class="col-sm-6">
<textarea id="comments" class="form-control request-textarea" type="text" onkeyup="checkMandatoryFields()"></textarea>
</div>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-sm-6 clearfix pull-right">
<button class="btn btn-default" onclick="handleCancel()">${gs.getMessage('Cancel')}</button>
<button id = "submit" class="btn btn-primary disabled" onclick="handleSubmit()">${gs.getMessage('Submit')}</button>
</div>
</div>
</div>
</div>
</div>
</j:jelly>
Client Script:
function checkMandatoryFields() {
var commentsElement = gel("comments");
var comments = commentsElement.value;
if (trim(comments) == '') {
gel('comments_label').removeClassName('is-filled');
gel('submit').addClassName('disabled');
gel('submit').writeAttribute('aria-disabled', true);
gel('submit').writeAttribute('tabindex', '-1');
} else {
gel('comments_label').addClassName('is-filled');
gel('submit').removeClassName('disabled');
gel('submit').writeAttribute('aria-disabled', false);
gel('submit').removeAttribute('tabindex');
}
}
function handleSubmit() {
var modal = GlideModal.get();
var actionName = modal.getPreference('methodName');
var commentsElement = gel("comments");
var comments = commentsElement.value;
comments = trim(comments);
if (comments != '') {
var sysId = gel('recordsysid').value;
var gr = new GlideRecord("tableName");
gr.addQuery("sys_id", sysId);
gr.query();
if (gr.next()) {
gr.state = 4;
gr.comments = comments;
gr.update();
}
}
GlideModal.get().destroy();
gsftSubmit(null, g_form.getFormElement(), actionName);
}
function handleCancel() {
GlideModal.get().destroy();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader