Search code examples
javascriptdynamics-crmcrmdynamics-crm-2013

How to find name and information about views of entity using javascript in dynamics crm


I want to find the name and columns set in all Views of entity of dynamic crm with the use of javascript.

enter image description here

This names for entity display in above image and columns which are set in view.


Solution

  • "Saved Query" is the entity that holds all the data related to system views. However getting the columns will require some parsing as the "Grid" is stored as an xml in the "LayoutXml" attribute of the entity.

    For e.g. to fetch views on "contact" entity:

    OData:

    GET [Organization URI]/api/data/v8.0/savedqueries?$select=name,layoutxml&$filter=returnedtypecode eq 'contact'
    

    FetchXml (Use SDK.js or XrmServiceToolkit):

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="savedquery">
        <attribute name="name" />
        <attribute name="layoutxml" />
          <filter type="and">
            <condition operator="eq" attribute="returnedtypecode" value="2"/>
          </filter>
      </entity>
    </fetch>
    

    Sample "LayoutXml" for "Active Contacts" view:

    <grid name=\"resultset\" object=\"2\" jump=\"fullname\" select=\"1\" icon=\"1\" preview=\"1\"><row name=\"result\" id=\"contactid\"><cell name=\"fullname\" width=\"200\" /><cell name=\"telephone1\" width=\"100\" /><cell name=\"mobilephone\" width=\"100\" /><cell name=\"telephone2\" width=\"100\" /><cell name=\"fax\" width=\"100\" /><cell name=\"emailaddress1\" width=\"150\" /><cell name=\"address1_line1\" width=\"100\" /><cell name=\"address1_line2\" width=\"100\" /><cell name=\"address1_city\" width=\"100\" /><cell name=\"address1_postalcode\" width=\"100\" /><cell name=\"parentcustomerid\" width=\"150\" /></row></grid>
    

    Parsing the xml for all cell elements you would get the view columns (e.g.):

    <cell name=\"fullname\" width=\"200\" />
    <cell name=\"telephone1\" width=\"100\" />