Hiding task transition buttons
This capability is necessary when you need to hide a button on a task form depending on some conditions.
A Razor form for hiding a transition button depending on whether the current executor belongs to a specific group. The button, which must be hidden, is identified by its ID.
@using EleWise.ELMA.Services;
@using EleWise.ELMA.Security.Services;
@using EleWise.ELMA.Security.Models;
@using EleWise.ELMA.Security.Managers;
<script type=’text/javascript’>
{
@{
var currentUser =
Locator.GetServiceNotNull<IAuthenticationService>().GetCurrentUser<IUser>();
var BSCReturn = UserGroupManager.Instance.Load("Administrators");
bool InGroup =
UserGroupManager.Instance.GetUsersByGroup(BSCReturn.Id).Any(a => a == currentUser.Id);
}
$(document).ready(function(){
if (’@InGroup’ ==’False’)
{
$(’#con033c201f746140cb84c7c3c8b438b940’).hide(); // after # specify the transition ID
}
});
}
</script>
The task form for a user, included in the Administrators group:
The task form for a user, not included in the Administrators group:
An example of a Razor form for hiding a button and its description depending on its value in the context:
Context variable: Flag – Yes/No type.
<script type="text/javascript">
@{
bool flag = ((dynamic)Model.Entity).Flag; // Flag – context variable name
}
$(document).ready(function(){
if (’@flag’ ==’False’)
{
$(’#con033c201f746140cb84c7c3c8b438b940’).hide(); // after # specify the transition ID
$(’#con033c201f746140cb84c7c3c8b438b940’).parent().parent().find(’.comment’).hide();
}
});
</script>