0
votes

I have code that sets the PXDataFieldAssign value as follows:

pf = new PXDataFieldAssign<xTACProjectTask.dueDate>(someValue);

I also have a table, holding the DAC field names, such as "xTACProjectTask.dueDate". This table also has a checkbox field to determine whether to use this DAC field as a parameter.

Is there a way to not have the DAC fieldname hard-coded, and instead (maybe using a 'typeof' call?) use the results of the table query to set that field name - like the following?

pf = new PXDataFieldAssign<typeof("xTACProjectTask.dueDate")>(someValue);

or, using my query result:

pf = new PXDataFieldAssign<typeof(query.value)>(someValue); 

with query.value being the value in the table holding the DAC field name?

1

1 Answers

0
votes

You can create it using Type.GetType and Activator.CreateInstance. Please see the example below:

string typeName = "PX.Objects.IN.InventoryItem+descr,PX.Objects";
Type typeArgument = Type.GetType(typeName);
Type genericClass = typeof(PXDataFieldAssign<>);
Type constructedClass = genericClass.MakeGenericType(typeArgument);
object created = Activator.CreateInstance(constructedClass,new object[] { "Test Description" });

You will get the below wrapped into object in the created

enter image description here