在SOOrder屏幕上:我有OrderType:C1,C2,CS,SO和C1-> userRole A,C2-> userRole B,CS& SO-> userRole管理员。我想通过userlogin选择默认的Ordertype,如果userlogin = Admin,那么显示选择器是CS&所以。 这是我的代码编辑器:SOOrderEntry(销售订单):
protected void SOOrder_OrderType_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
PXResult<PX.SM.UsersInRoles> user = PXSelect<PX.SM.UsersInRoles,
Where<PX.SM.UsersInRoles.username, Equal<Current<AccessInfo.userName>>>>.Select(Base);
if(user != null)
{
PX.SM.UsersInRoles role = user;
if(role.Rolename == "Administrator")
e.NewValue = "CS";
else
if(role.Rolename == "A")
e.NewValue = "C1";
if(role.Rolename == "B")
e.NewValue = "C2";
}
}
我的结果是:登录我们的角色管理员时,它显示了所有订单类型。
答案 0 :(得分:0)
您可以尝试以下
public class CustomOrderTypeSelectorAttribute : PXCustomSelectorAttribute
{
public CustomOrderTypeSelectorAttribute()
: base(typeof(SOOrderType.orderType))
{
}
public IEnumerable GetRecords()
{
PXResult<PX.SM.UsersInRoles> user = PXSelect<PX.SM.UsersInRoles,
Where<PX.SM.UsersInRoles.username, Equal<Current<AccessInfo.userName>>>>.Select(Base);
if(user != null)
{
PXResult<SOOrderType> orderTypes = null;
if(roleName == "Administrator")
{
orderTypes = PXSelect<SOOrderType,
Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>,
Or<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>>.Select(Base, "CS", "SO");
}
else if(roleName == "A")
{
orderTypes = PXSelect<SOOrderType,
Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.Select(Base, "C1");
}
else if(role.Rolename == "B")
{
orderTypes = PXSelect<SOOrderType,
Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.Select(Base, "C2");
}
foreach (var item in orderTypes)
yield return item;
}
}
}
然后使用附加的缓存来覆盖OrderType属性,并使用上面的自定义选择