Skip to main content
Answer

Restrict a field based on value on another field

  • May 14, 2025
  • 2 replies
  • 61 views

kristianharianja
Semi-Pro I
Forum|alt.badge.img+3

I guess this may require a customisation. Is it possible to restrict Shipping Rule in a sales order (making it read-only) if the Term of that order is X only for people who have user role Y?  

Best answer by aiwan

Hi ​@kristianharianja 

 

Yes, this will be a customisation.

You could configure the field via access rights, but I am not sure of the interactions that would occur if you are trying to control via access rights for the user role, and based on the shipping role via code.

You could use a method like below:

public static bool IsUserRole(string roleName, PXGraph graph)
{
string usrName = graph.Accessinfo.UserName;

UsersInRoles assignedRoles = SelectFrom<UsersInRoles>.
Where<UsersInRoles.username.IsEqual<P.AsString>.
And<UsersInRoles.rolename.IsEqual<P.AsString>>>.View.Select(graph, usrName, roleName);
if (assignedRoles == null)
return false;

else
{
if(graph.YourView.Current.ShippingRule == "YourShippingRule")
return true;
}

return false;
}

Then implement this like so:

PXUIFieldAttribute.SetVisible<YourDAC.yourField>(e.Cache, row, IsUserRole("Administrator", this));

Hope this helps!

2 replies

Forum|alt.badge.img+8
  • Captain II
  • Answer
  • May 14, 2025

Hi ​@kristianharianja 

 

Yes, this will be a customisation.

You could configure the field via access rights, but I am not sure of the interactions that would occur if you are trying to control via access rights for the user role, and based on the shipping role via code.

You could use a method like below:

public static bool IsUserRole(string roleName, PXGraph graph)
{
string usrName = graph.Accessinfo.UserName;

UsersInRoles assignedRoles = SelectFrom<UsersInRoles>.
Where<UsersInRoles.username.IsEqual<P.AsString>.
And<UsersInRoles.rolename.IsEqual<P.AsString>>>.View.Select(graph, usrName, roleName);
if (assignedRoles == null)
return false;

else
{
if(graph.YourView.Current.ShippingRule == "YourShippingRule")
return true;
}

return false;
}

Then implement this like so:

PXUIFieldAttribute.SetVisible<YourDAC.yourField>(e.Cache, row, IsUserRole("Administrator", this));

Hope this helps!


kristianharianja
Semi-Pro I
Forum|alt.badge.img+3

Thanks ​@aiwan for pointing me to the right direction.