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

Sam Ogden
Tera Guru

Hi All,

 

Thanks for the responses, I've got this working for the filed on our Incident form.

The only thing I have ran into is we use a UI action 'pending' to change the state to pending and make the u_pending_type field visible.  This UI action opens up a dialogue window that contains the pending type field and additional comments field.

The pending type field still displays all options to all users.  How can I restrict the options in the field in the dialogue window?

find_real_file.png

UI Action Script:

function makemandatory()
{
	g_form.setVisible('u_pending_type',true);
	
	var gdw = new GlideDialogWindow('u_incident_pending');
	gdw.setTitle('Pending Details');
	gdw.setSize(400,300);
	gdw.render();
}
if(typeof window == 'undefined')
	runBusRuleCode();
function runBusRuleCode()
{
	current.state=10;
	current.update();
	action.setRedirectURL(current);
}

 

 

Just been looking and the dialogue window is a UI page.  I've never dealt with these so not sure on what I need to amend within this to get the choice list restriction to apply.

UI Page 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 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>

UI Page Client Script:

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();
}

I'm guessing that the client script needs adding to, but not sure on the syntax required, any suggestions are greatly appreciated.

Thanks

Sam

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

 

Hi Tushar,

Thanks for the above.

Got this working now

Thanks

Sam

Hi Tushar,

 

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. 

Any help would be really appreciated.

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

How do i add another condition to it for the second part i.e. group with prefix?

 

Regards,

Surabhi