Post

1 follower Follow
0
Avatar

Can anyone help me out with PHP code to query GroupProjectLinks but only for active projects?

I tried, but I can't make it work. I'm trying to nest a query in the main where, like in  https://success.clarizen.com/entries/38249296-Query-ResourceLinks-f... . Thank you for any help!

 

$clarizenAPI = new clarizen_PHP_API_Client();

//Get Groups Info

$Fields = array('Group.Name', 'Entity.Name', 'Entity.Manager', 'Entity.State', 'Entity.DueDate', 'Entity.ActualEffort', 

'Entity.BudgetedHours', 'Entity.PlannedRevenue', 'Entity.ActualCost');

$LeftExpression = array("FieldName" => "Entity");

//***********************************************************************************************************************************************

$qLeftExpression = array (

"FieldName" => "State");

$qRightExpression = array (

"Value" => new SoapVar ('Active', XSD_STRING, "string", " http://www.w3.org/2001/XMLSchema")));

$qExpression = array (

"LeftExpression" => new SoapVar ($qLeftExpression,SOAP_ENC_OBJECT, "FieldExpression", " http://clarizen.com/api/queries"),

"Operator" => "Equal",

"RightExpression" => new SoapVar ($qRightExpression,SOAP_ENC_OBJECT, "ConstantExpression"," http://clarizen.com/api/queries")));

$qWhere = new SoapVar ($qExpression, SOAP_ENC_OBJECT, "Compare", " http://clarizen.com/api/queries");

//***********************************************************************************************************************************************

$query = array('TypeName' => 'Project', 'Where' => $qWhere);

$RightExpression = new SoapVar ($query,SOAP_ENC_OBJECT, "EntityQuery"," http://clarizen.com/api/queries");

$Expression = array (

"LeftExpression" => new SoapVar ($LeftExpression,SOAP_ENC_OBJECT, "FieldExpression", " http://clarizen.com/api/queries"),

"Operator" => "Equal",

"RightExpression" => new SoapVar ($RightExpression,SOAP_ENC_OBJECT, "QueryExpression"," http://clarizen.com/api/queries")));

$Where = array (new SoapVar ($Expression,SOAP_ENC_OBJECT, "Compare", " http://clarizen.com/api/queries")));

$clarizenTime = $clarizenAPI->getList('GroupProjectLink', $Fields, '', $Where);

Marketing Mojo IT Answered

Please sign in to leave a comment.

5 comments

0
Avatar

Hi there.

Several things you need to mend (fixed code below)

  1. For State field which is a pickup, you need to use an EntityId value (not directly 'Active').
  2. For a sub-query you need to use the In operator ( not 'Equal').
  3. The QueryExpression type has a property named Query which holds the EntityQuery

Hope this helps,

Ophir

$qRightExpression = array (

"Value" => new SoapVar ( array ("TypeName" => "State", "Value" => "Active"), SOAP_ENC_OBJECT, "EntityId", "http://clarizen.com/api"));

$qExpression = array (

"LeftExpression" => new SoapVar ($qLeftExpression,SOAP_ENC_OBJECT, "FieldExpression", "http://clarizen.com/api/queries"),

"Operator" => "Equal",

"RightExpression" => new SoapVar ($qRightExpression,SOAP_ENC_OBJECT, "ConstantExpression","http://clarizen.com/api/queries"));

$qWhere = new SoapVar ($qExpression, SOAP_ENC_OBJECT, "Compare", "http://clarizen.com/api/queries");

//***********************************************************************************************************************************************

$query = array('TypeName' => 'Project', 'Where' => $qWhere);

$RightExpression = array ("Query" => new SoapVar ($query,SOAP_ENC_OBJECT, "EntityQuery","http://clarizen.com/api/queries"));

$Expression = array (

"LeftExpression" => new SoapVar ($LeftExpression,SOAP_ENC_OBJECT, "FieldExpression", "http://clarizen.com/api/queries"),

"Operator" => "In",

"RightExpression" => new SoapVar ($RightExpression,SOAP_ENC_OBJECT, "QueryExpression","http://clarizen.com/api/queries"));

$Where = array (new SoapVar ($Expression,SOAP_ENC_OBJECT, "Compare", "http://clarizen.com/api/queries"));

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Ophir,

Thanks for the updated code! I've still got something messed up, somewhere. When I runt he code, I get: string(32) "Cannot create an abstract class."

 

Here is my code (basically what you gave me):

$Fields = array('Group.Name', 'Entity.Name', 'Entity.Manager.DisplayName', 'Entity.State', 'Entity.DueDate', 'Entity.ActualEffort',

'Entity.BudgetedHours', 'Entity.PlannedRevenue', 'Entity.ActualCost', 'Entity.TrackStatus', 'Entity.ExternalID');

$qLeftExpression = array ("FieldName" => "State");

$qRightExpression = array (

        "Value" => new SoapVar ( array ("TypeName" => "State", "Value" => "Active"), SOAP_ENC_OBJECT, "EntityId",  

        "http://clarizen.com/api"));

$qExpression = array (

        "LeftExpression" => new SoapVar ($qLeftExpression,SOAP_ENC_OBJECT, "FieldExpression",

        "http://clarizen.com/api/queries"),

        "Operator" => "Equal",

        "RightExpression" => new SoapVar ($qRightExpression,SOAP_ENC_OBJECT,

        "ConstantExpression","http://clarizen.com/api/queries"));

$qWhere = new SoapVar ($qExpression, SOAP_ENC_OBJECT, "Compare", "http://clarizen.com/api/queries");

$query = array('TypeName' => 'Project', 'Where' => $qWhere);

$LeftExpression = array("FieldName" => "Entity");

$RightExpression = array ("Query" => new SoapVar ($query,SOAP_ENC_OBJECT,

        "EntityQuery","http://clarizen.com/api/queries"));

$Expression = array (

        "LeftExpression" => new SoapVar ($LeftExpression,SOAP_ENC_OBJECT, "FieldExpression",

        "http://clarizen.com/api/queries"),

        "Operator" => "In",

        "RightExpression" => new SoapVar ($RightExpression,SOAP_ENC_OBJECT,

        "QueryExpression","http://clarizen.com/api/queries"));

$Where = array (new SoapVar ($Expression,SOAP_ENC_OBJECT, "Compare", "http://clarizen.com/api/queries"));

$clarizenReturn = $clarizenAPI->getList('GroupProjectLink', $Fields, '', $Where);

makePre($clarizenReturn); die();

 

 

 

And here is the code from the api client we wrote that is getting called:

function getList($TypeName, $Fields, $Paging = NULL, $Where = NULL)

{

try

{

//Create a Query object

$params = new stdClass();

//Set the name of the entity type you are querying

$params->TypeName = $TypeName;

//Select the fields you want retrieved from that entity

$params->Fields = $Fields;

//Set the Parameters, such as Page value and/or Page length

$params->Paging = $Paging;

!(is_null($Where)) ? $params->Where = $Where : '';

do

{

    $request = array();

    $request[] = new SoapVar($params, SOAP_ENC_OBJECT, 'EntityQuery', 'http://clarizen.com/api/queries');

    $result = $this->client->Execute(array("request"=>$request));

    if($result)

    {

        if ($this->displayErrors($result))

        {

            return $this->displayErrors($result);

        }

    }

    $params->Paging = $result->ExecuteResult->Result->Paging;

    $return[] = $result;

}while($result->ExecuteResult->Result->Paging->HasMore);

return $return;

}

catch(SoapFault $e)

{

//var_dump($result);

var_dump($e->getMessage());

}

}

Marketing Mojo IT 0 votes
Comment actions Permalink
0
Avatar

It's definitely part of the $Where. When I remark that out, things work fine.

Marketing Mojo IT 0 votes
Comment actions Permalink
0
Avatar

Hi Jeff (I assume you're Jeff from the previous post).

I believe you need to omit the array for $Where, e.g.:

$Where = new SoapVar ($Expression,SOAP_ENC_OBJECT, "Compare", " http://clarizen.com/api/queries"));

The Where property expects a Condition _and Compare_ is a Condition.

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Ophir,

Yep, that's me. And you are amazing. That worked perfectly! Thank you very much!

 

Jeff

Marketing Mojo IT 0 votes
Comment actions Permalink