ttajic
8/11/2015 - 9:13 AM

XrmServiceToolkit.Soap.Fetch

XrmServiceToolkit.Soap.Fetch

adacta.getConsumtionSegmentsForAccount = function(accountid, utilitytypeid) {
    if (XrmServiceToolkit === undefined || XrmServiceToolkit === null) {
        console.log('XrmServiceToolkit is not included on the form');
        return;
    }
    var resultObject;
    var fetchXml = 
        "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
        "<entity name='ad_consumptionsegment'>" +
        "<attribute name='ad_consumptionsegment' />" +
        "<attribute name='ad_customerid' />" + 
        "<attribute name='ad_utilitytype' />" +
        "<order attribute='modifiedon' descending='true' />" +
        "<filter type='and'>" +
        "<condition attribute='statecode' operator='eq' value='0' />" +
        "<condition attribute='ad_customerid' operator='eq' value='" + accountid + "' />" +
        "<condition attribute='ad_utilitytype' operator='eq' value='" + utilitytypeid + "' />" +
        "</filter></entity></fetch>";
    var resultObject = XrmServiceToolkit.Soap.Fetch(fetchXml);
    return resultObject;   
    // Object returned is an array of entities. Access atributes like this: resultObject[0].attributes.ad_customerid.value
};