Hide work order state on the asset work order form using role based
/// <summary>
/// Class EntAssetLifecycleStateUpdate event handlers
/// </summary>
class VTEntAssetLifecycleStateUpdateEventHandlers
{
/// <summary>
/// Post init based on role removing acces to finish
/// </summary>
/// <param name="args">Args</param>
[PostHandlerFor(formStr(EntAssetLifecycleStateUpdate), formMethodStr(EntAssetLifecycleStateUpdate, init))]
public static void EntAssetLifecycleStateUpdate_Post_init(XppPrePostArgs args)
{
SecurityRole role, systemAminRole;
SecurityUserRole userRole, systemAdminUserRole;
FormRun sender = args.getThis();
EntAssetTmpLifecycleStateUpdate lifecycleStateUpdate;
UserId userid = curUserId();
lifecycleStateUpdate = sender.dataSource(formdatasourcestr(EntAssetLifecycleStateUpdate, TmpLifecycleStateUpdate)).cursor();
#define.SystemAdmin('System administrator')
#define.VTMainatenceWorker('VT Maintenance worker')
#define.Finished('Finished')
#define.Canceled('Canceled')
#define.Incomplete('Incomplete')
select firstonly role
where role.Name == #VTMainatenceWorker;
select firstonly systemAminRole
where systemAminRole.Name == #SystemAdmin;
select firstonly userRole
where userRole.SecurityRole == role.RecId
&& userRole.User == userid;
select firstonly systemAdminUserRole
where systemAdminUserRole.SecurityRole == systemAminRole.RecId
&& systemAdminUserRole.User == userid;
if(userRole && !systemAdminUserRole)
{
select firstonly lifecycleStateUpdate
where lifecycleStateUpdate.LifecycleStateId == #Finished
&& lifecycleStateUpdate.Type == EntAssetLifecycleStateType::WorkOrder;
if(lifecycleStateUpdate)
{
delete_from lifecycleStateUpdate
where lifecycleStateUpdate.LifecycleStateId == #Finished
&& lifecycleStateUpdate.Type == EntAssetLifecycleStateType::WorkOrder;
}
// To Hide the Canceled state
select firstonly lifecycleStateUpdate
where lifecycleStateUpdate.LifecycleStateId == #Canceled
&& lifecycleStateUpdate.Type == EntAssetLifecycleStateType::WorkOrder;
if(lifecycleStateUpdate)
{
delete_from lifecycleStateUpdate
where lifecycleStateUpdate.LifecycleStateId == #Canceled
&& lifecycleStateUpdate.Type == EntAssetLifecycleStateType::WorkOrder;
}
// To Hide the Incomplete state
select firstonly lifecycleStateUpdate
where lifecycleStateUpdate.LifecycleStateId == #Incomplete
&& lifecycleStateUpdate.Type == EntAssetLifecycleStateType::WorkOrder;
if(lifecycleStateUpdate)
{
delete_from lifecycleStateUpdate
where lifecycleStateUpdate.LifecycleStateId == #Incomplete
&& lifecycleStateUpdate.Type == EntAssetLifecycleStateType::WorkOrder;
}
}
}
}
Comments
Post a Comment