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

Hi Shweta,

 

We've added the following on load client script.  This works in that people without the role cannot select the option from the list.  People with the role can.

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)
              g_form.removeOption('u_pending_type','Pending Release Board');
      else if (isRelMan){
              return;
      }
}

However if someone with the 'release_admin' selects the 'Pending Release Board' option, but then a user who does not have the role goes into the log they cannot read the option.

The field u_pending_type is a mandatory field on our form so it then makes the user without the role select another option.

What we want is only people with the release_admin role have the ability to select Pending Release Board.  If this has been selected other users should still be able to read this option and still select any other options from the list, but they cannot select this option.  Is this possible?

Thanks

Sam

Community Alums
Not applicable

Hi Sam,

 

have a condition on load client script.

if 'u_pending_type == Pending Release Board' && !isRelMan

g_form.setreadonly('u_pending_type ',true)

Tushar Sharma2
Kilo Guru

Hello Sam,

Write a On-load Client Script with below code in script.

  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 hide_field = g_form.getOption('u_pending_type','Pending Release Board');
        hide_field.setAttribute("disabled","true");
      }
       else if (isRelMan){
              return;
      }
}



Let me know if this works for you.

Hit Like or Correct on the impact of response.

-Tushar

 

Archana Reddy2
Tera Guru

This link may help you.

Disable options

Mark the answer as Correct/Helpful based on its impact.

Thanks

Archana Reddy2
Tera Guru

Hi,

The below onLoad client script should work.

function onLoad() {
	var role = g_user.hasRole('release_admin');
	if(!role)
		{
		var control = g_form.getControl('u_choice');
		control.options[1].disabled = true; //options[7] in your case
	}

Mark the answer as Correct/Helpful based on its impact.

Thanks,

Archana