Hi All ,
Initially, I defined the following parameters directly in the ER workspace:
From date
To date
Enterprise type
I was able to use these parameters in my ER filtering formula to filter the data. However, I moved the parameter declaration and validation to a custom ER contract class, because I noticed that standard ER contract classes handle parameter declaration and validation through X++ code. I also need the Enterprise Type parameter to support multi-selection.
I have implemented the following contract and UI Builder classes.
ER Contract
[DataContractAttribute]
class VT_MSMEERContract extends ERFormatMappingRunBaseContract
implements SysOperationValidatable, SysOperationInitializable
{
private FromDate fromDate;
private ToDate toDate;
private List enterpriseType;
[
DataMemberAttribute('FromDate'),
SysOperationLabelAttribute(literalstr("From date")),
SysOperationHelpTextAttribute(literalstr("From date")),
SysOperationDisplayOrderAttribute('1')
]
public FromDate parmFromDate(FromDate _fromDate = fromDate)
{
fromDate = _fromDate;
return fromDate;
}
[
DataMemberAttribute('ToDate'),
SysOperationLabelAttribute(literalstr("To date")),
SysOperationHelpTextAttribute(literalstr("To date")),
SysOperationDisplayOrderAttribute('2')
]
public ToDate parmToDate(ToDate _toDate = toDate)
{
toDate = _toDate;
return toDate;
}
[
DataMemberAttribute('EnterpriseType'),
AifCollectionTypeAttribute('return', Types::Enum, enumStr(VT_MSMEType)),
SysOperationLabelAttribute(literalstr("Enterprise type")),
SysOperationHelpTextAttribute(literalstr("Enterprise type")),
SysOperationDisplayOrderAttribute('3')
]
public List parmEnterpriseType(List _enterpriseType = enterpriseType)
{
enterpriseType = _enterpriseType;
return enterpriseType;
}
public boolean validate()
{
boolean ret = true;
if (fromDate == dateNull())
{
return checkFailed("@SYS91557");
}
if (toDate == dateNull())
{
return checkFailed("@SYS90868");
}
if (fromDate > toDate)
{
return checkFailed("@SYS120590");
}
return ret;
}
public void initialize()
{
fromDate = dateNull();
toDate = dateNull();
enterpriseType = new List(Types::Enum);
}
}
UI Builder
For the EnterpriseType parameter, I am using SysLookupMultiSelectCtrl so that the user can select multiple Enum values.
class VT_MSMEERUIBuilder extends SysOperationAutomaticUIBuilder
{
VT_MSMEERContract contract;
DialogField dialogEnterpriseType;
SysLookupMultiSelectCtrl multiSelectCtrl;
public void postBuild()
{
super();
contract = this.dataContractObject() as VT_MSMEERContract;
dialogEnterpriseType = this.bindInfo().getDialogField(
contract,
methodStr(VT_MSMEERContract, parmEnterpriseType));
}
public void postRun()
{
super();
if (dialogEnterpriseType && !multiSelectCtrl)
{
multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQueryRun(
this.dialog().dialogForm().formRun(),
dialogEnterpriseType.control(),
this.buildEnumQueryRun());
}
}
private QueryRun buildEnumQueryRun()
{
TmpSysQuery tmpTable;
DictEnum dictEnum = new DictEnum(enumNum(VT_MSMEType));
int i;
for (i = 0; i < dictEnum.values(); i++)
{
tmpTable.clear();
tmpTable.FieldLabel = dictEnum.value2Label(i);
tmpTable.insert();
}
Query query = new Query();
QueryBuildDataSource qbds =
query.addDataSource(tableNum(TmpSysQuery));
qbds.fields().dynamic(NoYes::No);
qbds.fields().addField(fieldNum(TmpSysQuery, FieldLabel));
QueryRun queryRun = new QueryRun(query);
queryRun.setCursor(tmpTable);
return queryRun;
}
public void getFromDialog()
{
#define.CollectionValueSeparator(';')
List selectedValues;
ListEnumerator selectedEnumerator;
List enumList = new List(Types::Enum);
str enumStrValue;
VT_MSMEType enumValue;
contract = this.dataContractObject() as VT_MSMEERContract;
super();
if (dialogEnterpriseType)
{
selectedValues = strSplit(
dialogEnterpriseType.value(),
#CollectionValueSeparator);
selectedEnumerator = selectedValues.getEnumerator();
while (selectedEnumerator.moveNext())
{
enumStrValue = selectedEnumerator.current();
enumValue = str2enum(enumValue, enumStrValue);
if (enum2str(enumValue))
{
enumList.addEnd(enumValue);
}
}
contract.parmEnterpriseType(enumList);
}
}
}
The multi-select lookup itself is working. I can select multiple Enterprise Type values from the report dialog, and those values are stored in the contract as a List of VT_MSMEType.
Where I am facing the problem
When the parameters were created directly in the ER workspace, I could use them in the ER filtering formula.
For example, my date filtering was working with the contract parameters:
WHERE(
VendTrans,
AND(
OR(
VendTrans.TransType = LedgerTransType.Purch,
VendTrans.TransType = LedgerTransType.Vend
),
OR(
'MSME Contract'.parmFromDate = NULLDATE(),
IF(
VendTrans.DocumentDate = NULLDATE(),
VendTrans.TransDate,
VendTrans.DocumentDate
) >= 'MSME Contract'.parmFromDate
),
OR(
'MSME Contract'.parmToDate = NULLDATE(),
IF(
VendTrans.DocumentDate = NULLDATE(),
VendTrans.TransDate,
VendTrans.DocumentDate
) <= 'MSME Contract'.parmToDate
)
)
)
The FromDate and ToDate values can now be accessed from the contract without any problem.
The difficulty is with:
parmEnterpriseType()
because this method returns:
List
containing multiple VT_MSMEType Enum values.
My question
Is it possible for an ER formula to consume a List of Enum values returned by a SysOperation/ER contract and use it in a filter condition?
I tried many times to cast it , but not able to do that, each I got error while saving the formula.