web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Using a List of Enum Values from an ER Contract in an ER Filter

(0) ShareShare
ReportReport
Posted on by 246

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.

Categories:
  • Suggested answer
    CU-1234529-002 Profile Picture
    631 on at

    Hi,

    This is possible, but not by passing the raw List of enum values directly ER formulas can't consume that type as-is. The documented way to do this is by converting your enum values to integers and passing them as a Record list parameter, then using VALUEIN or VALUEINLARGE in your filter formula instead of a direct equality comparison.

    So in your contract, when building the list to pass into the ER data source, convert each VT_MSMEType enum value to its integer equivalent using enum2int. Configure the EnterpriseType parameter on your ER data model as a Record list type, since the documented supported types for this kind of parameter are Boolean, Container, Date, DateTime, GUID, Int64, Integer, Real, and String, not Enum directly.

    Then in your filtering formula, instead of comparing the field directly to the enum, use something like VALUEIN(VendTrans.SomeEnumField, EnterpriseTypeList, EnterpriseTypeList.Value). This checks whether the field matches any value in the passed-in list, which gives you the multi-select IN style filtering you're after.

    Reference: https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/analytics/er-data-model-parameterized-calls , which walks through exactly this pattern of passing a list of values into a parameterized data model field and using VALUEIN or VALUEINLARGE in the formula.

    Thanks 

  • CU07100556-1 Profile Picture
    2 on at

    The multi-select setup looks solid, and the main challenge seems to be how ER handles the X++ List of enum values. It would be great to see a clean example of exposing the selected values in a way that ER can directly use for filtering. Thanks for sharing the detailed code and troubleshooting steps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 266 Super User 2026 Season 2

#2
Aayush Tiwari Profile Picture

Aayush Tiwari 217

#3
Subra Profile Picture

Subra 164 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans