Make Suspended Reason a Dependent Field in Dialog Box

ErinF
Tera Expert

I have a requirement to make the Suspended Reason of an HR Case dependent on the Topic Category of the case. I have configured the choice list as such from within the dictionary. When selecting the Suspended Reason from the Case Form, the dependency is working well. 

 

However, when using the UI action Suspend, the choices are not honoring the dependency. I understand that the reason for this is that the UI Page HR Suspend Dialog only queries the sys_choice table reasons for the field and does not have logic OOB to look for the field dependencies. 

 

Edit: I have some customized script in the HTML for the dialog box (will enter below). However, this script is not working as I would imagine. When the suspend dialog box is initiated, there are no values in the suspend reason drop-down.  Any edit suggestions on the script below that would fulfill this need?

 

Thanks for any input! I am very new to scripting, so please be kind 🙂 

 

<?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 topic_category = RP.getWindowProperties()["sysparm_topic_category"]?.left(indexOf(RP.getWindowProperties()["sysparm_topic_category"], '-')-1));
		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('dependent_value', RP.getWindowProperties()["sysparm_table_name"] || topic_category);
		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 ></span>${gs.getMessage('Work note')}  <!-- Removed class="required-marker" to make Worknote nonmandatory -->
						<!-- <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" rows="3" type="textarea" placeholder="${gs.getMessage('Work notes')}" name="suspend_comments" />
				<!-- 	<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 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>

 

 

2 REPLIES 2

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

Sorry if I misunderstood something, but shouldn't this line

 

reasons.addQuery('dependent_value', suspension_table);

 

be rather

 

reasons.addQuery('dependent_value', suspension_category);

 

?

 

That script was working correctly without that change. I have made an update to the post with a slight change.