Post

1 follower Follow
0
Avatar

Can I get PHP version of Links of parent-child example like in API guide?

Hi there,

I'm working an API to create a task and link to a project as a child.

I could create a project and a child using PHP API, but I cannot find a way to link them as "WorkItemHierarchyLink".

I'm not familiar with C#.Net and I need make it with PHP to run automatically daily to combine existing scripts.

 

Can I get PHP version of Links of parent-child example in "Working with References" in API guide?

 

Thanks,

 

Isaac Jeong Answered

Please sign in to leave a comment.

4 comments

0
Avatar

Hi Isaac.

Check this out. Hope it helps.

 

// Create task

//Create an entity representing the new task

$newTask = new stdClass();

$newTask->Id = new stdClass();

$newTask->Id->TypeName = 'Task';

$newTask->Id->Value = null;

//Set Task name

$nameField = new stdClass();

$nameField->FieldName = "Name";

$nameField->Value = new SoapVar("My Task", XSD_STRING, "string",

"http://www.w3.org/2001/XMLSchema");

//Set task start date

$startDateField = new stdClass();

$startDateField->FieldName = "DueDate";

$date = '2012-05-01';

$startDateField->Value = new SoapVar($date, XSD_DATETIME, "dateTime",

"http://www.w3.org/2001/XMLSchema");

//Assign the fields to the task

$newTask->Values = array($nameField, $startDateField);

$createMeesage = new stdClass();

$createMeesage->Entity = new SoapVar($newTask, SOAP_ENC_OBJECT,

"GenericEntity", 'http://clarizen.com/api');

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

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

$responseJSON = json_encode($result);

echo $responseJSON . "<br/><br/>";

$new_id = $result -> ExecuteResult -> Result -> Id;

$responseJSON = json_encode($new_id);

echo $responseJSON . "<br/><br/>";

// Link

 

$link = new stdClass();

$link->Id = new stdClass();

$link->Id->TypeName = 'WorkItemHierarchyLink';

$parent_project = array ("TypeName"=>"Project", "Value" => "803c569a-786e-401f-92bb-8bcbe07776bd");

$parent = new stdClass();

$parent->FieldName = 'Parent';

$parent->Value = new SoapVar($parent_project, SOAP_ENC_OBJECT, "EntityId","http://clarizen.com/api");

$child = new stdClass();

$child->FieldName = 'Child';

$child->Value = new SoapVar($new_id, SOAP_ENC_OBJECT, "EntityId","http://clarizen.com/api");

$link->Values = array($parent, $child);

$createMeesage = new stdClass();

$createMeesage->Entity = new SoapVar($link, SOAP_ENC_OBJECT, "GenericEntity", 'http://clarizen.com/api');

$request = array();

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

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

$responseJSON = json_encode($result);

echo $responseJSON . "<br/><br/>";

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Ophir,

Thanks a million! It perfectly works!

What I changed is the parent ID for my existing project and it worked and added a new task under the project!

I really appreciate it.

Isaac.

Isaac Jeong 0 votes
Comment actions Permalink
0
Avatar

Hi Issac,

Sure, the parent ID had to be changed, that was my intention.

You're most welcome, we're here for you any time.

Don't forget to mark this as useful.

Thanks.

Ophir

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Ophir,

This is very useful.

But I cannot mark my post as a useful since this web page seems not allow originator to do it.

I marked other posts you answered as userful. :-)

Thanks a lot.

Isaac Jeong 0 votes
Comment actions Permalink