This project is read-only.

Anyone know why there's a problem with my Fetch query? (Code inside)

Jun 20, 2013 at 11:21 AM
Edited Jun 20, 2013 at 11:22 AM
I have a FetchXML query, that keeps returning an "undefined" error. Anyone know why I'm getting an error, (code below):
function DataCheck() {

    var AccountC;

    var fetchXml = "<fetch mapping='logical'>" +
                   "<entity name='account'>" +
                   "<attribute name='name' />" +
                   "<attribute name='address1_city' />" +
                   "<attribute name='telephone1' />" +
                   "<attribute name='accountnumber' />" +
                   "<attribute name='new_primarypartner' />" +
                   "<attribute name='emailaddress1' />" +
                   "<attribute name='accountid' />" +
                   "<filter type='and'>" +
                   "<condition attribute='telephone1' operator='eq' value='995-0151' />" +
                   "</filter>" +
                   "</entity>" +

                fetchXml: fetchXml,
                async: false,
                successCallback: function (result) {
                    AccountC =  result.entities[0].accountid.Name;
                errorCallback: function (error) {
                    throw error;

            return AccountC;   
Jun 20, 2013 at 12:20 PM
The error you're getting has nothing to do with the toolkit. The problem is on the following line:
AccountC =  result.entities[0].accountid.Name;
accountid is Guid (passed as string), and property 'Name' is undefined. Which is exactly what you're getting.

Jun 20, 2013 at 12:24 PM
Thanks for the reply. I've looked at the samples but not sure how I can change it to get it to work. Any suggestions?
Jun 20, 2013 at 12:32 PM
Thanks Georged, I fixed it by going over my code properly.

For anyone else, the line that fixed it was this: AccountC = result.entities[0].name;