-1

I want to fetch logical name of attributes are in main form of account entity from systemform entity using javascript.And also Want to save that names in array or list.

Please Suggest me proper query and how to get name of each attribute from response.

Code:

        var serverUrl;
        serverUrl = location.protocol + "//" + location.host;
        function getformfields() {
            debugger;
            var oDataUri = "systemforms?$select=formxml&$filter=name eq 'account'";
            var data = getODataRecords(oDataUri);
            if(data!=null&&data!="")
            {
               //how to get field name from response
            }

        }
        function getODataRecords(ODataUrl) {
            debugger;
            var data;
            var Query = ODataUrl;
            var req = new XMLHttpRequest();

            req.open("GET", serverUrl + "/api/data/v8.0/" + Query, false);
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
            req.onreadystatechange = function () {
                if (this.readyState == 4 /* complete */) {
                    req.onreadystatechange = null;
                    if (this.status == 200) {
                        data = JSON.parse(this.response);
                    }
                    else {
                        var error = JSON.parse(this.response).error;
                        alert(error.message);
                    }
                }
            };
            req.send();
            return data;

        }
chhaya_patel
  • 171
  • 1
  • 2
  • 15

1 Answers1

1

It is just a matter of parsing the result formxml property.

The only thing to be aware of, is if an attribute is added multiple times, the control's id is appended with a numeric suffix e.g. name1, name2 etc. The datafieldname attribute points to the attribute the control is referring to.

var data = getODataRecords(oDataUri);
if (data && data.value && data.value[0] && data.value[0].formxml) {
 var xml = jQuery(data.value[0].formxml);
 var controls = xml.find('control');
 jQuery.each(controls, function(index, control) {
     console.log(jQuery(control).attr('datafieldname'));
 });
}
dynamicallyCRM
  • 2,980
  • 11
  • 16
  • Hello, Thanx for reply. I get all fields but for address1_composite field it displays only address1_composite.Is there any way to find the attribute street1,stree2,street3,city,state,zip and country.which are open in the form when we click on a Address field. – chhaya_patel Oct 20 '16 at 09:02
  • Hi, when we click on form button then there is field explorer on right side of form which has the fields. is this possible to get that fields display in field explorer? – chhaya_patel Oct 20 '16 at 09:20