Skip to main content
Solved

How to solve the following error: GenericArguments[0], 'AddFilterOnProjectTaskWeekly.ProjTaskAttribute+CONTAINS_LABOUR', on 'PX.Data.Current`1[Field]' violates the constraint of type parameter 'Field'.

  • November 30, 2023
  • 2 replies
  • 225 views

Forum|alt.badge.img
public class ProjTaskAttribute : ProjectTaskAttribute
{
public const string Labor = "LABOR";
public ProjTaskAttribute(Type projectID) : base(projectID)
{

Type Labor = typeof(CONTAINS_LABOUR);
Type SearchType =
BqlCommand.Compose(
typeof(Search<,>),
typeof(PMTask.taskID),
typeof(Where<,,>),typeof(PMTask.projectID),typeof(Equal<>),typeof(Current<>),projectID,
typeof(And<,>),typeof(PMTask.description),typeof(Like<>),typeof(Current<>), Labor
);

PXDimensionSelectorAttribute select = new PXDimensionSelectorAttribute(DimensionName, SearchType, typeof(PMTask.taskCD),
typeof(PMTask.taskCD), typeof(PMTask.description), typeof(PMTask.status));
select.DescriptionField = typeof(PMTask.description);
select.ValidComboRequired = true;

_Attributes.Add(select);
_SelAttrIndex = _Attributes.Count - 1;

Filterable = true;
}

public sealed class CONTAINS_LABOUR : BqlType<IBqlString, string>.Constant<CONTAINS_LABOUR>
{
/// <exclude/>
public CONTAINS_LABOUR() : base("LABOR") { }
}
}

How to solve the following error: GenericArguments[0], 'AddFilterOnProjectTaskWeekly.ProjTaskAttribute+CONTAINS_LABOUR', on 'PX.Data.Current`1[Field]' violates the constraint of type parameter 'Field'.

 

 

Best answer by allisterchambers48

I had this same error message; it looks to have been caused by incorrect [PXParent] attributes on child tables. They were in the form:

[PXParent(typeof(SelectFrom<Parent>,Where<Parent.Field,IsEqual<Parent.Field.FromCurrent>>>)]

But needed to be

[PXParent(typeof(SelectFrom<Parent>,Where<Parent.Field.IsEqual<Child.Field.FromCurrent>>>)]

 

And make sure that if you have two or more fields in the child defining the link to the parent, then use them both/all in the one PXParent:

[PXParent(typeof(SelectFrom<Parent>,Where<Parent.Field1.IsEqual<Child.Field1.FromCurrent»

.And<Parent.Field2.IsEqual<Child.Field2.FromCurrent>>>>)]

Otherwise you’ll find the delete cascades to any record that has (Field1 = parent OR Field2 = parent).

Note there’s also the LeaveChildren flag if you don’t want the parent delete to cascade to that child table.

2 replies

Forum|alt.badge.img+1

I had this same error message; it looks to have been caused by incorrect [PXParent] attributes on child tables. They were in the form:

[PXParent(typeof(SelectFrom<Parent>,Where<Parent.Field,IsEqual<Parent.Field.FromCurrent>>>)]

But needed to be

[PXParent(typeof(SelectFrom<Parent>,Where<Parent.Field.IsEqual<Child.Field.FromCurrent>>>)]

 

And make sure that if you have two or more fields in the child defining the link to the parent, then use them both/all in the one PXParent:

[PXParent(typeof(SelectFrom<Parent>,Where<Parent.Field1.IsEqual<Child.Field1.FromCurrent»

.And<Parent.Field2.IsEqual<Child.Field2.FromCurrent>>>>)]

Otherwise you’ll find the delete cascades to any record that has (Field1 = parent OR Field2 = parent).

Note there’s also the LeaveChildren flag if you don’t want the parent delete to cascade to that child table.


Forum|alt.badge.img+1

@Rajginoya 

Can you also add how the ProjTaskAttribute is used? 

I couldn’t replicate using this custom attribute.