Hi team.
I am trying to build a dynamic SugarQuery, the scenario is that I have an array of "fields" I want to use to create a dynamic select statement. For simplicity the $selectGenerator array below contains name and id.
$sugarQuery = new SugarQuery(); $sugarQuery->from(BeanFactory::newBean($filename),array('team_security' => false)); foreach($selectGenerator as $field) { $field = "'" . trim($field) . "'"; print "select(array($field))" . "</br>"; $sugarQuery->select(array($field)); } $sugarQuery->select(array('billing_address_street')); $result = $sugarQuery->execute();
The above query only returns the "billing_address_street" field and not name and ID as expected.
If I manually updated the array to NOT use the variable and instead by hard coded (the exact same string) it works.
$sugarQuery = new SugarQuery(); $sugarQuery->from(BeanFactory::newBean($filename),array('team_security' => false)); foreach($selectGenerator as $field) { $field = "'" . trim($field) . "'"; print "select(array($field))" . "</br>"; $sugarQuery->select(array('id')); } $sugarQuery->select(array('billing_address_street')); $result = $sugarQuery->execute();
I've tried without the force quotes around name, and also without them, and it seems to always fail whenever I use a variable rather than hard coded.
For instance I checked to ensure it was generating the same and my code generates the correct format which would be:
select(array('name'))
select(array('id'))
Has anyone else gotten around this or is this a bug?
Thanks,
Daniel