Closed JoshNW closed 6 years ago
I have also tried simply updated the account team with out using a query first, and still not had any luck.
`$accountteam = new ATWS\AutotaskObjects\AccountTeam(); $accountteam ->AccountID = 3274; $accountteam ->ResourceID = 29682886;
$result = $client->update($accountteam);`
Looks like in your first post you printed out the response from the getZoneInfo call, not the account team update call.
Are you able to successfully auth?
Yes, I am able to successfully authenticate, I realized what that output was shortly after posting, I am unsure the best method to print the output of the update call.
If it should print without an additional line of code requesting it, then I have to assume that the call is simply failing.
After the call, you can do print_r($client->__getLastResponse());
I did get the command to execute.
I was able to use an Create, in stead of an Update.
$accountteam = new ATWS\AutotaskObjects\AccountTeam(); $accountteam -> AccountID = '3274'; $accountteam -> id= 0; $accountteam -> ResourceID = '29682889';
$result = $client->Create($accountteam);
This works fine for my purposes, although I am weary of how I will remove and manage individuals on these account teams in the future.
For reference, most of our customers have a Sales Rep that manages the accounts, as well as a service manager that is the single point of contact for service escalations, project reports, and other non-sales related customer service functions. There are cases where a second sales rep also assists the primary.
These names change around frequently, and thus a simple means to update the account teams is critical sustained use of the application. With no simple means to mange these teams within the UI the API appears to be the only option.
Do you have any suggestions to remove unnecessary records?
@JoshNW This is the first time I worked with the AccountTeam. It is makes sense that they are returned as individual objects.
I was able to come up with tested code to remove / manage individuals. You may want to modify to fit your needs.
//General Query
$accountId = 29704384;
$accountTeam = new \ATWS\AutotaskObjects\Query('AccountTeam');
$accountIdQueryField = new \ATWS\AutotaskObjects\QueryField('AccountID');
$accountIdQueryField->addExpression('equals',$accountId);
$accountTeam->addField($accountIdQueryField);
$members = $client->query($accountTeam)->queryResult->EntityResults->Entity;
//Add to team
$accountteam = new ATWS\AutotaskObjects\AccountTeam();
$accountteam->AccountID = $accountId;
$accountteam->id= 0;
$accountteam->ResourceID = 30845622;
// $result = $client->create($accountteam);
//Remove from team
$accountIdToRemove = 30845666;
$members = (is_array($members)) ? $members : [$members];
foreach ($members as $key => $value)
{
if($value->ResourceID === $accountIdToRemove)
{
$keyToRemove = $key;
}
}
if (isset($keyToRemove))
{
// $client->delete($members[$keyToRemove]);
}
@SirPoot Thank you! that helps a ton. One struggle will be determining which accounts need to be removed. We often receive a new account list with updated account teams and no reference to what they were before. I am considering simply clearing all entries and restarting on each pass, but that seems like it will be a great deal of overkill in most situations. I will keep playing with the code and post a follow up if I work out a better way.
@JoshNW you're welcome. If you do not have the issue anymore, can you please close this?
@JoshNW I had a task where I needed to remove old "inactive" from the AccountTeam because for some reason Autotask does not remove them when the resource is inactive and wanted to share my process.
I queried all the active resources and saved the Id's to an array. Then after querying the AccountTeam, looping through each member to see if the member is in the active resource array. If not, it adds the member to another array (accountTeamMembersToDelete). Once all the account teams are processed, it will perform a bulkDelete from the accountTeamMembersToDelete array. I saved the list of original and accountTeamMembersToDelete for recovery purposes.
I am currently unable to update account teams.
I am using the following code to select a single resource to add to the account team:
`$query = new ATWS\AutotaskObjects\Query('AccountTeam'); $AccountID = new ATWS\AutotaskObjects\QueryField('AccountID'); $AccountID->addExpression('Equals', '3274'); $query->addField($AccountID); $queryResult = $client->query($query);
$AccountTeam = $queryResult->queryResult->EntityResults->Entity; $AccountTeam->ResourceID = '29682886';
$result = $client->update($AccountTeam);`
I receive the following out put, but cannot determine why the account Team has not been updated.
stdClass Object ( [getZoneInfoResult] => ATWS\AutotaskObjects\ATWSZoneInfo Object ( [CI] => 305040 [DataBaseType] => [ErrorCode] => 0 [URL] => https://webservices14.autotask.net/ATServices/1.5/atws.asmx [WebUrl] => https://ww14.autotask.net/ ) )
any assistance would be greatly appreciated.