Urgent : Suspended Reason choices are not appearing for Non-admin users

nagadeepika
Kilo Contributor

On HR case form when the state is selected as Pending.... A Dialog pop up appears with Reason and worknotes to fill. The choices were added in sys_choice table and they are appearing for admin users.

For non-admin users Choices were NOT coming up.

I am unable to figure the rootcause

find_real_file.png

 

find_real_file.png

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please check the table level READ ACL on sys_choice table

Was it visible earlier to them?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Thanks for the immediate response. I am unaware if this was working earlier I doubt about it.

 I saw the acl's on sys_choice table. but i am not seeing anything specific.

find_real_file.png

 

In addition to add Non-admin users were able to see the choices on form page for that filed. It is happing on UI page

find_real_file.png

 

 

Hi,

is that OOB ui page? if yes then share name

If not then please share UI page HTML, Client script etc

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Please find the code

 

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:requires name="styles/heisenberg/heisenberg_all.css" includes="true" />
	<g:evaluate object='true' jelly="true">
		var suspension_type = RP.getWindowProperties()["sysparm_suspension_type"];
		var reasons = new GlideRecord('sys_choice');
		reasons.addQuery('name', 'sn_hr_core_case');
		reasons.addQuery('element','sla_suspended_reason');
		reasons.addQuery('language', gs.getSession().getLanguage());
		reasons.addQuery('inactive',false);
		reasons.orderBy('sequence');
		reasons.query();
		reasons;
	</g:evaluate>

	<g:ui_form id="HR Suspend Order">
		<!--
				Parameters
				sysparm_table - type of the object
				sysparm_suspension_type - type of suspension
				sysparm_state_sys_id - SysID of the suspended object state
				sysparm_order_sys_id - SysID of the object to suspend
				sysparm_ok_button_name - localized name for the ok button
		 -->
		<style type="text/css">
			#suspend_dialog_footer input {
				width: 100%;
			}
			#info_message {
				margin-left:10px;
				color:#667
			}
		</style>
		<div>
			<!--  Add onclick validation -->
			<div class="form-group has-error row">
				<label class="col-sm-3 control-label" style="text-align:right" for="suspend_reason">${gs.getMessage('Reason')}</label>
				<span class="col-sm-9">

					<select id="suspend_reason" class="form-control" name="suspend_reason">
						<j:while test='${reasons.next()}'>
							<j:if test="${reasons.getValue('value') == suspension_type}">
								<option value="${reasons.getValue('value')}" selected='selected'>${reasons.getValue('label')}</option>
							</j:if>
							<j:if test="${reasons.getValue('value') != suspension_type}">
								<option value="${reasons.getValue('value')}">${reasons.getValue('label')}</option>
							</j:if>
						</j:while>
					</select>
				</span>
			</div>

			<div class="form-group is-required row">
				<label for="suspend_comments" class="control-label col-sm-3" style="text-align:right">
					<span class="required-marker"></span>${gs.getMessage('Work note')}
				</label>
				<span class="col-sm-9">
					<input id="suspend_comments" class="col-sm-9 form-control" required="required" rows="3" type="textarea" aria-required="true" placeholder="${gs.getMessage('Work notes')}" name="suspend_comments" />
				</span>
			</div>
		</div>

		<footer id="suspend_dialog_footer" class="modal-footer">
			<input type="hidden" id="form_id" name="form_id" value="form.${sys_id}"></input>
			<input type="hidden" id="table" name="table" value="${sysparm_table}"></input>
			<input type="hidden" id="suspension_type" name="suspension_type" value="${sysparm_suspension_type}"></input>
			<input type="hidden" id="order_sys_id" name="order_sys_id" value="${sysparm_order_sys_id}"></input>
			<input type="hidden" id="button_clicked" name="button_clicked" value="ok"></input>
			<button type="button" id="cancel_button" class="btn btn-default" onClick="return submitCancel(); ">
				${gs.getMessage('Cancel')} 
			</button>
			<button id="ok_button" class="btn btn-primary" onClick="return submitOk();">
				${gs.getMessage('Ok')}
			</button>
		</footer>
	</g:ui_form>
</j:jelly>

 

client script:

function submitCancel(state) {
	GlideDialogWindow.get().destroy();
	return false;
}

function submitOk() {
	var result = $("suspend_comments").value != '';
	if (result) {
		$('cancel_button').addClassName('disabled');
		$('ok_button').addClassName('disabled');
	}
	return result;
}

// Because this UI page is displayed in form popups that
// should be submitted after the popup is confirmed, 
// we submit the form in the popup using an ajax call.
// Once we know that's done, the UI actions/client scripts
// handle submitting further changes on the form
addLoadEvent(function(){
	var formId = $('form_id').value.replace('.', '\\.');
	$j('#' + formId)
		.submit(function(evt) {
			var form = $j(this);
			var url = form.attr('action');
			$j.ajax({
				type: 'POST',
				url: url,
				data: form.serialize(), 
				success: function(data)
				{
					GlideDialogWindow.get().fireEvent('suspendSuccess');
				}
			});

			evt.preventDefault();
		});
});

 

Processing script:

(function(_this) {
	var urlOnStack = gs.getSession().getUrlOnStack();
	var taskCreated = false;
	var hrTask;

	if (table == 'sn_hr_core_task') {
		var task = new GlideRecord('sn_hr_core_task');
		task.get(order_sys_id);

		var siblings = new GlideRecord('sn_hr_core_task');
		siblings.addQuery('parent', task.parent.sys_id);
		siblings.addQuery('suspend_request', 'true');
		siblings.setValue('suspend_request', 'false');
		siblings.updateMultiple();

		task.suspend_request = true;
		task.request_suspension_reason = suspend_reason;
		task.work_notes = suspend_comments;
		task.update();

		var parentCase = new GlideRecord('sn_hr_core_case');
		// suspend the hr case when it is not already closed
		if (parentCase.get(task.parent) && (parentCase.state != 3 && parentCase.state != 4 && parentCase.state != 7 && parentCase.sla_suspended == false)) {
			parentCase.sla_suspended = true;
			parentCase.state = 24;
			parentCase.sla_suspended_on = new GlideDateTime().getDisplayValue();
			parentCase.sla_suspended_reason = task.request_suspension_reason;
			parentCase.update();
		}
	}
	else {
		var hrCase = new GlideRecord('sn_hr_core_case');
		hrCase.get(order_sys_id);
		hrCase.sla_suspended_reason = suspend_reason;
		hrCase.work_notes = suspend_comments;
		hrCase.sla_suspended = true;
		hrCase.state = 24;
		hrCase.sla_suspended_on = new GlideDateTime().getDisplayValue();
		hrCase.update();
	}

	response.sendRedirect(urlOnStack);
	if (taskCreated) {
		var message = gs.getMessage('Task created {0} for {1}', ['<a href="sn_hr_core_task.do?sys_id='+hrTask.sys_id+'">'+hrTask.number+'</a>', hrTask.assigned_to.name]);
		gs.addInfoMessage(message);
	}
})(this);