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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Reading Entity Customization xml through C#

(0) ShareShare
ReportReport
Posted on by 3,355

Hello Experts,

I would like to read a customization xml which contains Entity and attribute (picklist). Could you please help me to retrieve the values properly. Here is a part of Attributes XML.

      <attribute PhysicalName="featurearea">
        <Type>picklist</Type>
        <ValidForCreateApi>1</ValidForCreateApi>
        <ValidForUpdateApi>1</ValidForUpdateApi>
        <ValidForReadApi>1</ValidForReadApi>
        <IsCustomField>1</IsCustomField>
        <AttributeTypeId>00000000-0000-0000-00cc-220000000090</AttributeTypeId>
        <DisplayMask>ValidForAdvancedFind|ValidForForm|ValidForGrid</DisplayMask>
        <Descriptions>
          <Description description="Feature area of the case" languagecode="1033" />
        </Descriptions>
        <ImeMode>auto</ImeMode>
        <RequiredLevel>required</RequiredLevel>
        <AppDefaultValue>-1</AppDefaultValue>
        <options>
          <option value="3">
            <labels>
              <label description="Aaaa" languagecode="1033" />
            </labels>
          </option>
          <option value="4">
            <labels>
              <label description="Audio" languagecode="1033" />
            </labels>
          </option>
          <option value="17">
            <labels>
              <label description="Certification" languagecode="1033" />
            </labels>
          </option>
          <option value="10">
            <labels>
              <label description="Compiler/Linker" languagecode="1033" />
            </labels>
          </option>
          <option value="5">
            <labels>
              <label description="Config" languagecode="1033" />
            </labels>
          </option>
          <option value="11">
            <labels>
              <label description="CPU" languagecode="1033" />
            </labels>
          </option>
          <option value="1">
            <labels>
              <label description="Graphics" languagecode="1033" />
            </labels>
          </option>
          <option value="15">
            <labels>
              <label description="Kinect" languagecode="1033" />
            </labels>
          </option>
          <option value="16">
            <labels>
              <label description="Networking" languagecode="1033" />
            </labels>
          </option>
          <option value="12">
            <labels>
              <label description="System" languagecode="1033" />
            </labels>
          </option>
          <option value="19">
            <labels>
              <label description="Tools" languagecode="1033" />
            </labels>
          </option>
          <option value="7">
            <labels>
              <label description="fdfgdg" languagecode="1033" />
            </labels>
          </option>
          <option value="6">
            <labels>
              <label description="Video" languagecode="1033" />
            </labels>
          </option>
          <option value="13">
            <labels>
              <label description="Other" languagecode="1033" />
            </labels>
          </option>
          <option value="14">
            <labels>
              <label description="Deprecated – Value" languagecode="1033" />
            </labels>
          </option>
          <option value="20">
            <labels>
              <label description="Deprecated – Comp" languagecode="1033" />
            </labels>
          </option>
          <option value="2">
            <labels>
              <label description="Deprecated – hhhh" languagecode="1033" />
            </labels>
          </option>
          <option value="18">
            <labels>
              <label description="Deprecated – Pppp" languagecode="1033" />
            </labels>
          </option>
          <option value="9">
            <labels>
              <label description="Deprecated – Web Services" languagecode="1033" />
            </labels>
          </option>
          <option value="8">
            <labels>
              <label description="Deprecated – llll" languagecode="1033" />
            </labels>
          </option>
        </options>
        <displaynames>
          <displayname description="Feature Area" languagecode="1033" />
        </displaynames>
      </attribute>

I would like to read option values and labels.

Best Regards,

Saroj

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi Saroj,

    This is same as you are reading any xml file in C# code..

    You can use XMLReader to read xml and get required values from XML.

    Here are some examples of how to read xml file in C#.

    support.microsoft.com/.../307548

    msdn.microsoft.com/.../cc189056(v=vs.95).aspx

    msdn.microsoft.com/.../aa287537(v=vs.71).aspx

    csharp.net-informations.com/.../how-to-read-xml.htm

    www.dotnetperls.com/xmlreader

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    I am just curious why you need to read customization xml in C#.net .. if you want to retrieve picklist text, then you can use entity metadata.

    CRM has RetrieveAllEntitiesRequest, you can use this to retrieve all entities and attributes

    metadata.. This will give you all details which you have in customization xml file.

    Here is a example of how to retrieve  Picklist metadata.

    msdn.microsoft.com/.../jj602916.aspx

    Attributes meta data..

    msdn.microsoft.com/.../gg309435.aspx

    All about metadata

    msdn.microsoft.com/.../gg309539.aspx

    Also in CRM SDK, Microsoft gave some sample code on how to retrieve metadata..

    It's under sdk\samplecode\cs\metadata

  • Royal King Profile Picture
    27,686 on at

    Here is the code that can retrieve name and value of the optionset value fromt he xml you posted

    var attributeXml = " <attribute PhysicalName=\"featurearea\">" +

                           "        <Type>picklist</Type>" +

                           "        <ValidForCreateApi>1</ValidForCreateApi>" +

                           "        <ValidForUpdateApi>1</ValidForUpdateApi>" +

                           "        <ValidForReadApi>1</ValidForReadApi>" +

                           "        <IsCustomField>1</IsCustomField>" +

                           "        <AttributeTypeId>00000000-0000-0000-00cc-220000000090</AttributeTypeId>" +

                           "        <DisplayMask>ValidForAdvancedFind|ValidForForm|ValidForGrid</DisplayMask>" +

                           "        <Descriptions>" +

                           "          <Description description=\"Feature area of the case\" languagecode=\"1033\" />" +

                           "        </Descriptions>" +

                           "        <ImeMode>auto</ImeMode>" +

                           "        <RequiredLevel>required</RequiredLevel>" +

                           "        <AppDefaultValue>-1</AppDefaultValue>" +

                           "        <options>" +

                           "          <option value=\"3\">" +

                           "            <labels>" +

                           "              <label description=\"Aaaa\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"4\">" +

                           "            <labels>" +

                           "              <label description=\"Audio\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"17\">" +

                           "            <labels>" +

                           "              <label description=\"Certification\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"10\">" +

                           "            <labels>" +

                           "              <label description=\"Compiler/Linker\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"5\">" +

                           "            <labels>" +

                           "              <label description=\"Config\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"11\">" +

                           "            <labels>" +

                           "              <label description=\"CPU\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"1\">" +

                           "            <labels>" +

                           "              <label description=\"Graphics\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"15\">" +

                           "            <labels>" +

                           "              <label description=\"Kinect\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"16\">" +

                           "            <labels>" +

                           "              <label description=\"Networking\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"12\">" +

                           "            <labels>" +

                           "              <label description=\"System\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"19\">" +

                           "            <labels>" +

                           "              <label description=\"Tools\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"7\">" +

                           "            <labels>" +

                           "              <label description=\"fdfgdg\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"6\">" +

                           "            <labels>" +

                           "              <label description=\"Video\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"13\">" +

                           "            <labels>" +

                           "              <label description=\"Other\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"14\">" +

                           "            <labels>" +

                           "              <label description=\"Deprecated – Value\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"20\">" +

                           "            <labels>" +

                           "              <label description=\"Deprecated – Comp\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"2\">" +

                           "            <labels>" +

                           "              <label description=\"Deprecated – hhhh\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"18\">" +

                           "            <labels>" +

                           "              <label description=\"Deprecated – Pppp\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"9\">" +

                           "            <labels>" +

                           "              <label description=\"Deprecated – Web Services\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "          <option value=\"8\">" +

                           "            <labels>" +

                           "              <label description=\"Deprecated – llll\" languagecode=\"1033\" />" +

                           "            </labels>" +

                           "          </option>" +

                           "        </options>" +

                           "        <displaynames>" +

                           "          <displayname description=\"Feature Area\" languagecode=\"1033\" />" +

                           "        </displaynames>" +

                           "      </attribute>";

               var element = XElement.Parse(attributeXml).Descendants("option");

               var options = from option in element

                                select new { Vale = option.Attribute("value").Value, Name = option.Element("labels").Elements("label").First<XElement>().Attribute("description").Value };

               foreach (var option in options)

               {

                   Console.WriteLine(option.Name + "    :  " + option.Vale);

               }

               Console.Read();

  • Saroj Das Profile Picture
    3,355 on at

    Hi Chitrarasan and Mahadeo, Thank you very much for your valuable response and time. Apologize for not clearing the question. Actually i want to do a data import to crm 2015. I have only entities xml file. where i have to read the attributes and create entity with these attributes. I am able to create other attributes except the picklist and lookup. I don't want to use OOB data import. As the options are nested, so getting some difficulties to read the values and labels.  Please suggest.

    Best regards,

    Saroj

  • Royal King Profile Picture
    27,686 on at

    check the CRM sdk which has sample code to create meta data for all kind of attributes.

    under folder SDK\SampleCode\CS\Metadata\Attributes

    Lookup attribute is handled differently so you have to check sample code under  

    SDK\SampleCode\CS\Metadata\Relationships

  • Mahadeo Matre Profile Picture
    17,021 on at

    Saroj,

    In this case either you can use XMLreader in C# or Chitra's code to get option set text and values and use those to create attributes in CRM.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans