Page MenuHomePhorge

How to run "WHERE custom field = something" in PHP
Closed, ResolvedPublic

Asked by valerio.bozzolan on Mar 5 2024, 15:58.
Tags
None
Referenced Files
None
Subscribers
Tokens
"Love" token, awarded by valerio.bozzolan.

Details

How to use PHP to query Maniphest Tasks by a custom field?

I expect something like this:

$custom_field_name = 'custom:zabbix.trigger.id';
$condition_value = 123;

$task = ( new ManiphestTransactionQuery() )
        ->setViewer( $viewer )
        ->setConditionByCustomFieldButWhatIsTheNameOfThisMethod( $custom_field_name, $condition_value )
        ->executeOne();

Thanks for any tip. I'm writing a small extension and I need to find a Task by a custom value.

Answers

avivey
Updated 53 Days Ago

Got this to work, using a Standard custom field:

$engine = new ManiphestTaskSearchEngine();

$task = new ManiphestTask();

$field_key = 'std:maniphest:custom-list.hours';

$field = PhabricatorCustomField::getObjectField(
  $task,
  PhabricatorCustomField::ROLE_APPLICATIONSEARCH,
  $field_key);

$query_value = '222';

$query = ($engine->newQuery())
  ->setViewer($viewer);

$field->applyApplicationSearchConstraintToQuery(
  $engine,
  $query,
  $query_value);


$res = $query->executeOne();

echo(pht("Found task with id: %d \n", $res->getID()));

New Answer

Answer

This question has been marked as closed, but you can still leave a new answer.