Notifications
Announcements
No record found.
Hi everyone
I have a dialog that has a Enum based on that I need to perform operations on data.
can you help me create a switch case which uses Enum as input.
*This post is locked for comments
Hi RamPrasad,
Here is code from msdn article https://msdn.microsoft.com/en-us/library/aa629483.aspx
switch (myEnum) { case ABC::A: ... break; case ABC::B: ... break; case ABC::C: ... break; default: ... break; }
Hi Ram Prasad,
This Code is used to import data from CSV you can put your enum value in switch().
switch (str2enum(campaignStatus,strLRTrim((conPeek(readcon,3)))))
{
case smmCampaignStatus::Planning:
campaignTable.CampaignStatus = smmCampaignStatus::Planning;
break;
case smmCampaignStatus::FollowUp:
campaignTable.CampaignStatus = smmCampaignStatus::FollowUp;
case smmCampaignStatus::Cancelled:
campaignTable.CampaignStatus = smmCampaignStatus::Cancelled;
case smmCampaignStatus::Closed:
campaignTable.CampaignStatus = smmCampaignStatus::Closed;
case smmCampaignStatus::InProcess:
campaignTable.CampaignStatus = smmCampaignStatus::InProcess;
case smmCampaignStatus::Response:
campaignTable.CampaignStatus = smmCampaignStatus::Response;
}
check this link for dialog that has enum value
howtoax.com/dialogenumcombobox-class-in-ax-2012
It worked Thanks
but I tried a different method I
took a integer variable and assigned enum from dialog to it and used switch on that varible
You can check this peace of code that might be help
DictEnum dictEnum = new DictEnum(enumId);
int numEnum;
;
// Test 1: we have a variable of desired Enum type (salesPurchIn of type SalesPurch), we can use the str2enum function
numEnum = 0;
while(numEnum < dictEnum.values())
if(label == dictEnum.index2Label(numEnum))
info(int2str(dictEnum.index2value(numEnum)));
numEnum++;
// Test 2: we don't have any variable, but we know the EnumId
salesPurchOut = str2enum(salesPurchIn, label);
info(int2str(salesPurchOut));
// Test 3: we can do it with name2label anyway...
for more information check below link
howtoax.com/how-to-get-integer-variable-and-assigned-enum-from-dialog-in-ax-2012-using-x
RamPrasad: It's true that enums are actually integers under the hood, but is using numbers instead of enums really better? Using numeric constant used to be the practice in older programming languages, before enums were invented to make code easier to write, verify at compile time, make it more readable and so on.
That there is another solution doesn't always mean that it makes sense to use it.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 4 Most Valuable Professional
Priya_K 4
MyDynamicsNAV 2