Fetchxml query in javascript in HTML webresource Dynamics CRM 2011

Associate
Joined
27 Jan 2005
Posts
1,347
Location
S. Yorks
I have a fetchxml query on a webresource in dynamics crm 2011, all works well apart from if a row contains null in which case the column is not returned for the row.

How can I check to ensure the row contains all of the columns required and if there is a column missing allocate a "" to the field requiring this value?

Code:
 var _oService;
            var _sOrgName = "A_CRMSystem";
            var _sServerUrl = window.parent.Xrm.Page.context.getServerUrl();

            var pcode = "a postcode";
            var sFetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
                                  "<entity name='a_postalcode'>"+
                                  "<attribute name='a_postalcode' />"+
                                  "<attribute name='a_country' />"+
                                  "<attribute name='a_city' />"+
                                  "<attribute name='a_postalcodeid' />"+
                                  "<attribute name='a_street3' />"+
                                  "<attribute name='a_street2' />"+
                                  "<attribute name='a_street1' />"+
                                  "<order attribute='a_country' descending='false' />"+
                                  "<order attribute='a_postalcode' descending='false' />"+
                                  "<filter type='and'>"+
                                  "<condition attribute='a_postalcode' operator='eq' value='"+ pcode +"' />"+
                                  "</filter>"+
                                  "</entity>"+
                                  "</fetch>";
            _oService = new FetchUtil(_sOrgName, _sServerUrl);
            var res = _oService.Fetch(sFetch);
 
           for (var i = 0; i < res.length; i++)
           {
                var fn1 = "";
                var fn2 = "";
                var fn3 = "";
                fn1 = res[i].attributes["orb_street1"].value;
                fn2 = res[i].attributes["orb_street2"].value;
                fn3 = res[i].attributes["orb_street3"].value;
                bindData(tableID, fn1, fn2, fn3);
            }

regards,

Matt
 
Sorted this now, had to modify the utility javascript file that I was using to include an additional reference to the name and return that.

My next question is, with the fetch xml string above, sFetch, what is the best way to strip out the attribute names, e.g. I want to end up with a list with just
a_postalcode
a_country
a_city
a_postalcodeid
a_street3
a_street2
a_street1

regards,

Matt
 
Its amazing how when I always ask questions, after spending a few hours struggling away, I seem to always find an answer!

Simply use the XMLDOM and pass the text into it!

Matt
 
Back
Top Bottom