Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Restrict Choice List Options based on Group

Sam Ogden
Tera Guru

Hi All,

 

We have a choice list field on the incident form of 'pending state'  this has 5 options.  We want to add a 6th option to the list but we only want our SM Release team to be able to select this option, how can we achieve this ?

Thanks

Sam

1 ACCEPTED SOLUTION

Tushar Sharma2
Kilo Guru

Hey Sam,

Good News for you. I worked on your code and was able to restrict the choice.

1. Add below code in UI HTML Page.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<script>
addLoadEvent( function()
{
  onLoad();
});

</script>
	
<g:evaluate>
 var types = GlideScriptChoiceList.getChoiceList('incident', 'u_pending_type');
</g:evaluate>
	<style>
		.hide_this
		{
		display:none;
		}
	</style>
	
	<div style="padding-bottom: 10px;">
	<span style="float: left;padding-left: 10px;">Pending Type : </span>

		<select id="pendingType" style="margin-left: 20px;" onChange = "show_3rdparty_fields()">
			<j:forEach var="jvar_choice" items="${types}">                   
			   <option value="${jvar_choice.value}">${jvar_choice.label}</option>
			 </j:forEach>
		</select><br/> 
	<br/>
	<div class ="hide_this" id = 'partysupplier'>
	<span style="float: left;padding-left: 10px;">3rd Party Supplier : </span>
	<g:ui_reference name="supplier" id="supplier" table="core_company" query="manufacturer=true^ORvendor=true"/>
	</div>
	<br/>
	<div class='hide_this' id = 'partyreference'><span style="float: left;padding-left: 10px;">3rd Party Reference : </span>
	<input type = "text" id = 'pref' style ="padding-right: 5px; width: 55%;"/></div>
</div>

	<div style="padding-left: 10px;">
		<span>Additional Comments (Customer Visible)</span>
   <div>
			<textarea rows="4" cols="50" id="comments" style="margin-top: 5px;">
			</textarea>
	</div>
	</div>	
	<div style="padding-left: 10px;">
		
		<input type="button" value="Submit" onClick="return submit()" style="float:left;margin-right: 15px;"/>
		<input type="button" value="Cancel" onClick="return cancel()"/>
	</div>
</j:jelly>

 

2.Add below onLoad function into UI Page Client Script to restrict choice list options based on role.

function onLoad()
 {
   //Type appropriate comment here, and begin script below
	//Remove option of "Pending Release Baord" from anyone except Release Management
      var isRelMan = g_user.hasRole('release_admin');
      if (!isRelMan)
      {
       var opt=gel("pendingType");
       opt.options[6].disabled = true;
      }
      else
      {
        return;
      }
}



function submit()
{
	var pendingType = gel('pendingType').value;
	var comments = gel('comments').value;
	
	var thirdsupplier = $j('#supplier').val();
	var thirdreference = $j('#pref').val();
	if(pendingType != '' && comments.trim() != '')
		{
		g_form.setValue('u_pending_type',pendingType);
		g_form.setValue('comments',comments);
		g_form.setValue('incident.correlation_display',thirdsupplier);
		g_form.setValue('incident.correlation_id',thirdreference);
		gsftSubmit(null, g_form.getFormElement(), 'setpending');
	}
	else
		{
		alert('Please fill the details');
	}
}

function show_3rdparty_fields()
{
	var pending_type = $j("#pendingType option:selected").val();
	
	if(pending_type == 'Pending Other Party')
		{
		$j('#partysupplier').show();
		$j('#partyreference').show();
	}
	else{
		$j('#partysupplier').hide();
		$j('#partyreference').hide();
	}
	
}


function cancel()
{
	g_form.setValue('u_pending_type','');
	g_form.setValue('comments','');
	GlideDialogWindow.get().destroy();
}

 

Let me know if this works for you.

 

Hit Like or Correct on the impact of response.

-Tushar

 

View solution in original post

16 REPLIES 16

SnowDEV2
Kilo Expert

Hi All,

 

I do have similar requirement to hide one of the choice value from Pending type. I tried below code, but it works fine in IE but not working in Chrome? 

Can anyone help how to make it work for Chrome as well

 

function onLoad(){

var asgngrp = g_form.getDisplayBox('assignment_group').value;
if(asgngrp.indexOf('CSC') > -1){
var opt=gel("pendingType");
alert(opt);
opt.options[3].disabled = true;
}
else
{
return;
}
}

Hi,

I have a requirement to restrict the problem closure based on role (problem manager) and group(with a prefix "xyz").

I was able to achieve this requirement partially i.e. for the role the restriction has been updated and works fine using below code. How do i add another condition to it for the second part i.e. group with prefix?

Any help would be really appreciated.

var isPrbMan = g_user.hasRole('Problem Manager');
if (!isPrbMan)
g_form.removeOption('state','6');
else if (isPrbMan) {
return;
}

 

Regards,

Surabhi