SugarQuery - Aggregates not working..

Hi Folks

Running a query in MySQL. it's working but the same I'm trying with SugarQuery not getting any result.

Query..

MySQL Query - 

SELECT enjay_tally_group_c, count(0) AS record_count 

FROM tl_tally_ledger_cstm 
GROUP BY enjay_tally_group_c

And same trying with SugarQuery.

$sugarQuery = new SugarQuery();
$SugarQuery->select(array('enjay_tally_group_c'))->setCountQuery();
$sugarQuery->from(BeanFactory::newBean("tl_Tally_Ledger"));
$SugarQuery->groupByRaw('tl_tally_ledger.enjay_tally_group_c');
$sugarQuery->select(array('enjay_tally_group_c'));
$sugarQuery_result = $sugarQuery->execute();

Whats wrong in above sugarquery.

Francesca Shiekh  André Lopes Ajay Kumar Angel Magana

Thanks

Mehul

  • Hi Mehul,

    The logicwise the sugar query formation that you formed is pretty good.
    In your code ,I see that you have created sugar query object like "$sugarQuery = new SugarQuery();" (lowercase "sugarQuery")
    But you have formed query with "$SugarQuery"(initial capital) object.And again trying to execute it with "$sugarQuery".(lowercase "sugarQuery").

    Can you please correct it with same case and check it once.

    With Best Regards

    Ajay Kumar B

  • Hi Ajay Kumar

    Thanks, brother.

    The problem was the same that you have observed.  

    Actually, I have copied that line from support portal so not changed. 

    Sharing working code.

    $sugarQuery = new SugarQuery();
    $sugarQuery->select(array('enjay_tally_group_c'))->setCountQuery();
    $sugarQuery->from(BeanFactory::getBean("tl_Tally_Ledger"));
    $sugarQuery->groupByRaw('enjay_tally_group_c');
    $sugarQuery->select(array('enjay_tally_group_c'));
    $sugarQuery_result = $sugarQuery->execute();