Hi,
I'm trying to create a quick query that will return a list of service call entities and the count of related tasks to that service call. I have tried this 2 ways and have issues with both.
Here is the actual SQL query I'm expecting to be executed:
SELECT servicecall.gpservicecallid, Count(task.id) as Task_Count
FROM servicecall
LEFT OUTER JOIN task ON task.servicecallid = servicecall.id
GROUP BY servicecall.gpservicecallid
Option 1 uses the executeFromXML method:
This option causes the app to hang when it is called
function GetTasksByServiceCallXml() {
var xmlData = '<fetch version="1.0" resultformat="Array" aggregate="true">' +
'<entity name="servicecall">'+
'<attribute name="gpservicecallid" alias="gpservicecallid" groupby="true" />'+
'<link-entity name="task" from="servicecallid" to="id" link-type="outer" />' +
'<entity name="task">' +
'<attribute name="servicecallid" alias="task_count" aggregate="countcolumn"/>' +
//'<attribute name="gpservicecallid" alias="gpservicecallid" groupby="true" />'+
'</link-entity>' +
'</entity>' +
'</fetch>'
MobileCRM.FetchXml.Fetch.executeFromXML(
xmlData,
DisplayTaskCount,
function (err) {
alert('Error occured: ' + err);
},
null
)
}
Option 2 uses the MobileCRM.FetchXml.Fetch method returns an error and the response has no data:
function GetTasksByServiceCall() {
var entity = new MobileCRM.FetchXml.Entity("servicecall");
entity.addAttribute("gpservicecallid");
entity.attributes[0].groupby = true;
entity.attributes[0].alias = "gpservicecallid";
var linkEntity = entity.addLink("task", "servicecallid", "id", "outer");
linkEntity.alias = "task";
linkEntity.addAttribute("gpservicecallid");
linkEntity.attributes[0].aggregate = "count";
linkEntity.attributes[0].alias = "task_count";
var fetch = new MobileCRM.FetchXml.Fetch(entity);
fetch.aggregate = true;
fetch.execute("Array",
DisplayTaskCount,
DisplayTaskError,
null
);
}
What I'm expecting to be outputted is this:
ServiceCall: [CallID] - Tasks: [Task Count]