Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Reading Enum From Excelsheet

Posted on by 434

I am having a Table named as M_Account . This table has 4 Fields. the Fourth field is a Enum Field named as Resource Category . In a Excel Sheet There are Four fields as same as M_Account Table. I have to Read the Enum Field from excel sheet and i have to Insert that Enum Data into the M_Account Table . 

_rescat = str2enum(cells.item(row,4).value().bStr());

I am facing an error wrong number of arguments has been specified for the method . 

Please give the solution for me and i am new to AX. 

Thanks in Advance,

Ram.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Reading Enum From Excelsheet

    Ram, I think I provided you the solution in my previous post above. Did you not notice it?

  • Ram Kumar Profile Picture
    Ram Kumar 434 on at
    RE: Reading Enum From Excelsheet

    Hi André,

    This is my Spreadsheet the last field is an Enum in my table i have to  read that data from the spreadsheet and i have to store that in a variable. All the other fields in my table are String fields. 

    3730.Excel1.png

    _accountstruct = cells.item(row, 2).value().bStr();
    _expcat = cells.item(row, 3).value().bStr();

    _rescat = str2enum(cells.item(row,4).value().bStr());

    Here i succesfully Readed the data for the String fields and i stored in a string variable . But i can't able to read the Res_Cat field from the spreadsheet and store in a enum variable . 

    I need syntax for the code to read the data from the spreadsheet and to store in an enum variable .

    Thanks in advance,

    Ram.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Reading Enum From Excelsheet

    I suggest you use standard data entities, then you don't have to think about such things at all.

    Anyway, if you want to convert string to enum, please continue reading.

    When you type "str2Enum(" you see the tooltip which says you must provide two parameters: enum type and the text. This is very important information for a developer so it's good to get familiar with utilizing such documentation that is provided you during development.

    Having to provide the enum type is quite obvious, because otherwise there would not be enough information for the conversion. Many enums might have options that have the same name. So how would the system know which enum it is, unless you tell it?

    For example, to convert text "Invoiced" into SalesStatus enum value "Invoiced", you call str2enum(SalesStatus, "Invoiced"). Is it now clear?

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    RE: Reading Enum From Excelsheet

    Hi Ram,

    The data import/export framework is able to read Excel files and do the import for you which also takes enum fields in consideration. Have you had a look at this framework? Or what is the reason that you started developing something with x++ coding? What is the business process here?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans