GroupBy and ForEach

May 7, 2013 at 9:53 PM
Edited May 7, 2013 at 9:54 PM
Hi

I need use GroupBy, I am processing crm data
function GetArrayFromFetchResults(fetchResults) {

    var entityResults = new Array();

    var entityElems = fetchResults.getElementsByTagName("a:Entity");

    for (var i = 0; i < entityElems.length; i++) {

        entityResults[i] = new Object();
        
        entityResults[i].id = GetFieldValue(entityElems[i], "accountid");
        entityResults[i].name = GetFieldValue(entityElems[i], "name");

        entityResults[i].latitude = GetFieldValue(entityElems[i], "address1_latitude");
        entityResults[i].longitude = GetFieldValue(entityElems[i], "address1_longitude");

        entityResults[i].zona = GetFieldValue(entityElems[i], "new_zona");
        entityResults[i].sucursal = GetFieldValue(entityElems[i], "new_sucursalprincipal");
        entityResults[i].vendedor = GetFieldValue(entityElems[i], "new_vendedorasigandoid");

    }
   
    return entityResults;
}
I need group result by "sucursal", end then use the ForEach(), but I don´t find the correct parameters
var resultArray = GetArrayFromFetchResults(resultCRM);

Enumerable.From(resultArray)
                                .GroupBy("$.sucursal",
                                    function(key, group) { return { sucu: key, grupo: group} })
                                .ForEach(alert($.sucu + ' ' + $.grupo));
greetings
Coordinator
May 8, 2013 at 7:47 AM
GroupBy has three arguments.

for example
// keySelector, elementSelector, resultSelector
// group is Enumerable
Enumerable.From(resultArray)
    .GroupBy("$.sucursal", "", function (key, group) { return { sucu: key, group: group } })
    .ForEach(function (x) { alert(x.sucu + ' ' + x.group.Select("$.name").ToString(",")) });
May 9, 2013 at 3:42 PM
hi

thanks, works perfect


greetings