- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2018 05:59 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2018 12:46 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2018 11:36 PM
Hi,
To hide and show option there is a method by name removeOption(). This method will hide options based on your condition.
Regards,
Shweta K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 01:20 AM
Hi Shweta,
Thanks for the above. How would I best incorporate this? would it be best as an on load client script on the form to check if the user is a member of a certain group, if not then remove option?
Thanks
Sam

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 01:44 AM
Yes, it is the best.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 01:48 AM
Hi,
Yes, use above code in onLoad() client script.
Regards,
Shweta K