You may need to adjust Join operator . Generate fetchxml using advancd find or XRM toolbox Fetchxml Builder
https://fxb.codeplex.com/
Below script should get what you are looking for.
function getServiceAppointments(territoryId) {
var fetchXml='<fetch>'+
' <entity name="serviceappointment" >'+
' <attribute name="actualend" />'+
' <attribute name="actualstart" />'+
' <attribute name="activityid" />'+
' <filter>'+
' <condition attribute="statecode" operator="eq" value="3" />'+
' <condition attribute="statuscode" operator="eq" value="4" />'+
' </filter>'+
' <link-entity name="activityparty" from="activityid" to="activityid" link-type="inner" >'+
' <link-entity name="equipment" from="partyid" to="equipmentid" link-type="inner" >'+
' <filter>'+
' <condition attribute="aar_territoryid" operator="eq" value="'+territoryId+'" />'+
' <condition attribute="aar_resourcetype" operator="eq" value="3" />'+
' </filter>'+
' </link-entity>'+
' </link-entity>'+
' </entity>'+
'</fetch>';
//request SOAP envelope for the encoded fetchXML query
var request = [
'<s:Envelope xmlns:s="schemas.xmlsoap.org/.../"><s:Body>',
'<Execute xmlns="schemas.microsoft.com/.../Services" xmlns:i="www.w3.org/.../XMLSchema-instance" >',
'<request i:type="a:RetrieveMultipleRequest" xmlns:a="schemas.microsoft.com/.../Contracts">',
'<a:Parameters xmlns:b="schemas.datacontract.org/.../System.Collections.Generic">',
'<a:KeyValuePairOfstringanyType>',
'<b:key>Query</b:key>',
'<b:value i:type="a:FetchExpression">',
'<a:Query>', encodeFetch(fetchXml), '</a:Query>',
'</b:value>',
'</a:KeyValuePairOfstringanyType>',
'</a:Parameters>',
'<a:RequestId i:nil="true"/>',
'<a:RequestName>RetrieveMultiple</a:RequestName>',
'</request>',
'</Execute>',
'</s:Body></s:Envelope>'
].join("");
//Synchronous XMLHttpRequest to retrieve contact records
var req = new XMLHttpRequest();
req.open("POST", encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web"), false);
try { req.responseType = 'msxml-document' } catch (e) { }
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction","<a href="schemas.microsoft.com/.../Execute">schemas.microsoft.com/.../Execute</a>");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null; //Addresses potential memory leak issue with IE
if (this.status == 200 /*success*/) {
var doc = req.responseXML;
// successCallback(doc);
}
else {
alert(accountId);
}
}
}
req.send(request);
}
function encodeFetch(strInput) {
var c;
var XmlEncode = '';
if (strInput == null) {
return null;
}
if (strInput == '') {
return '';
}
for (var cnt = 0; cnt < strInput.length; cnt++) {
c = strInput.charCodeAt(cnt);
if (((c > 96) && (c < 123)) ||
((c > 64) && (c < 91)) ||
(c == 32) ||
((c > 47) && (c < 58)) ||
(c == 46) ||
(c == 44) ||
(c == 45) ||
(c == 95)) {
XmlEncode = XmlEncode + String.fromCharCode(c);
}
else {
XmlEncode = XmlEncode + '&#' + c + ';';
}
}
return XmlEncode;
}