Skip to main content

Notifications

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

How to add enum values to AOT by through code by xml editing.

Posted on by 157

Hi every one,

I am doing some R&D on xml editing.

I had one test enum and it has two enum values pen and pencil. I want to add  a new element i.e node let us say scale.

class CreatingEnumThroughXml

{

   // public static void main(Args _args)

   // container strpath;

 

 

   public static void main(Args _args)

   {

       str path;

       

       //nodeXml = xDoc.createElement("scale")

       XmlElement xmlName ,xmlAXEnumValue,XmlValue;

       XmlNode  enumValues , AXEnumValue,AxValue;

       FileIoPermission permission;

        permission  =    new

            FileIoPermission("K:\AosService\PackagesLocalDirectory\HandelAndKontor\HandelAndKontor\AxEnum\TestEnum1.xml",'w');

     

       XmlText xmlNameText,xmlValueText;

 

      

        path = @"K:\AosService\PackagesLocalDirectory\mymodel\mymodel\AxEnum\TestEnum1.xml";

        XmlDocument xDoc = new XmlDocument();

        xDoc.Load(path);

        xmlName         =   xDoc.createElement("Name");

        XmlValue        =   xDoc.createElement("Value");

        xmlAXEnumValue  =   xDoc.createElement("AXEnumValue");

        AXEnumValue     =   xDoc.documentElement().selectSingleNode("EnumValues").appendChild(xmlAXEnumValue);

       // enumValues  = xDoc.documentElement().selectSingleNode("EnumValues").appendChild(xmlName);

        enumValues      =   AXEnumValue.appendChild(xmlName);

        AxValue         =   AXEnumValue.appendChild(XmlValue);

 

        xmlNameText = xDoc.createTextNode("Scale");

        xmlValueText= xDoc.createTextNode("2");

        enumValues.appendChild(xmlNameText);

        AxValue.appendChild(xmlValueText);

 

        xDoc.save(path);

     

       

}

 

}

For this new node is getting added to xml but it is not reflecting in the AOT.

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: How to add enum values to AOT by through code by xml editing.

    But what's point? You can't use this code outside development environments (runtime runs binaries, not source code) and in development environments, you have development tools for working with source code. If you want a code generator, write a Visual Studio extension instead of putting it into the business logic of your ERP system.

  • Neetha Profile Picture
    Neetha 157 on at
    RE: How to add enum values to AOT by through code by xml editing.

    Hi Nikolaos,

    We have created some AOT elements in the run time by creating an xml file. There is no business requirement I just want to explore can we change the AOT elements by editing the xml file or not.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: How to add enum values to AOT by through code by xml editing.

    You can't manipulate AOT elements in runtime in D365FO.

    What is your business requirement? If you need a dynamic list, don't use fixed list (enum). Instead store the list values in separate table. In standard system such examples are for example customer groups and payment terms.

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans