MSP Evolution - Autotask Configuration ItemsFor this example, we will build a Configuration Item called 'Internet Connection' that has several valuable User-Defined Fields.
Build a corresponding product called 'Internet Connection'.
Within the CRM module, locate a customer to add an Installed Product to.
Contact your Autotask Sales Representative and tell them you want to enable Data Warehousing. Please note, additional fees may apply.
They will request a range of public IPs that you will be connecting from. If you use cloud based servers, you may need to contact your provider to get this information.
PHP 5.2.6 (http://www.php.net)
Native MSSQL Libraries + any other libraries you wish to use.
This will work with IIS or Apache - there are a number of tutorials online to assist in this setup.
PHP MSSQL APACHE
PHP MSSQL IIS
If setting up webservers are not your thing, there are also a large number of cloud based providers with servers already ready to go!
http://www.nearlyfreespeech.net
Autotask will provide you with an email containing your Data Warehouse Connection information.
connect.php - save as connect.php
<?php
/*
// Autotask Data Warehousing is served from a MS SQL Server.
// Populate the variables below with the information they provide when
// Data Warehousing is set up.
//
// Microsoft SQL Server, TCP Port as provided by Autotask
$mssqlHost = "host,portnumber"; #It is MSSQL Instance name
//
// Warehouse Login as provided by Autotask
$mssqlUser = 'username';
//
// Warehouse Password as provided by Autotask
$mssqlPass = 'password';
//
// Database Name as provided by Autotask
$mssqlATDB = 'database name';
//
// pull all of that together into the connect string
$SQLConnect = mssql_connect($mssqlHost,$mssqlUser,$mssqlPass)
or die('Could not connect to SQL Server on '.$mssqlHost
.' '. mssql_get_last_message());
*/
$mssqlHost = "Reports.autotask.net,1433"; #It is MSSQL Instance name
$mssqlUser = 'user';
$mssqlPass = 'password';
$mssqlATDB = 'TF_8125000_WH';
$SQLConnect = mssql_connect($mssqlHost,$mssqlUser,$mssqlPass)
or die('Could not connect to SQL Server on '.$mssqlHost
.' '. mssql_get_last_message());
?>
Once you have built your 'connect.php' file, you can test your connection to the Data Warehouse using the file below.
You will see one of the two messages below, or additional PHP error messages.
checkConnection.php - save as checkConnection.php
OR
Autotask uses a data structure called 'Accounts' to store information about Customers, Vendors, Competitors, etc. This section focuses on how to pull information from the Data Warehouse related to 'Accounts' of type, 'Customer'.
In this example, we will build a simple list of customers that will look like this. (baby steps)
listCustomers.php - save as listCustomers.php
For simplicity in these examples, all files are 'self-contained' and do not reference common includes - aside from the previously mentioned 'connect.php' file.
<?php
//Include connect.php as it stores all remote database connection variables.
require_once("connect.php");
// simple function to take a query, run it against the data warehouse
// and return a multi-indexed array of the results, if any.
// if there are no results, the function returns 0.
function queryToArray($query){
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
if($numRows > 0){
while($row = mssql_fetch_assoc($result)){
$arrayOfCustomerInformation[] = $row;
}
return $arrayOfCustomerInformation;
}
else {
return 0;
}
}
//generic query to pull top 100 values from the wh_account table
//where the account_type_id = 1 (Customer)
// and is_active = 1 (Currently Active)
$query = "select
top(100)*
from
wh_account
where
account_type_id = '1' AND
is_active = '1'
";
//generic query to pull all values from the wh_account table
//(commented out)
//$query = "select * from wh_account";
//create an array of values that are returned by the query
$myCustomerArray = queryToArray($query);
//If there are results from the query, print them out to the
//screen.
// Brief explanation of this array:
// $myCustomerArray stores a multi-indexed array of accounts.
// each index ($k) is a unique customer account.
// each index ($k) has an associative array of key, value pairs
// that can be referenced by name like this
//
// $myCustomerArray[$k]["address_1"]
//
//NOTE: These may change over time!
/*
[account_id] => 0
[owner_resource_id] => 4
[create_time] => May 16 2002 6:56AM
[external_id] =>
[account_name] => Name
[directory_account_id] => 0
[address_1] => 1234 Fake St
[address_2] =>
[city] => Fakerton
[state] => VA
[zip_code] => 12345
[country] =>
[phone_number] => (555)555-1234
[alternate_phone_1] =>
[alternate_phone_2] =>
[fax_number] =>
[web_url] => http://www.customer.com
[account_type_id] => 1
[key_account_icon_id] =>
[territory_id] =>
[market_segment_id] => 29682845
[competitor_id] =>
[parent_account_id] =>
[stock_symbol] =>
[stock_market] =>
[sic_code] =>
[asset_value] =>
[last_activity_time] => Sep 26 2009 3:31PM
[external_accounting_id] =>
[is_active] => 1
[is_costed_client] => 0
[is_tax_exempt] => 0
[uses_parent_account_contracts] => 0
*/
echo "<hr>";
if($myCustomerArray != 0){
echo "<b>".count($myCustomerArray)." Active Customers</b>\n<br/>";
for($k=0;$k<count($myCustomerArray);$k++){
echo " ".$myCustomerArray[$k]["account_name"]."\n<br/>";
}
}
echo "<hr>";
//to quickly see all values returned, use the print_r function.
//(commented out.)
echo "<pre>\n";
print_r($myCustomerArray);
echo "</pre>\n";
?>
As you saw in the previous example, Autotask uses a data structure called 'Accounts' to store information about Customers, Vendors, Competitors, etc. This section focuses on how to pull information from the Data Warehouse related to 'Accounts' of type, 'Vendor'.
In this example, we will build a simple list of Vendors that will look like this. (more baby steps)
In comparing the source for Vendors and Customers, there is only a minor difference - the 'account_type_id'.
For Vendors, this value is 7.
For Customers, this value is 1.
The other major difference is the output - there is more information about the vendors printed back to the screen.
You can easily do this with Customer Accounts as well.
listVendors.php - save as listVendors.php
For simplicity in these examples, all files are 'self-contained' and do not reference common includes - aside from the previously mentioned 'connect.php' file.
<?php
//Include connect.php as it stores all remote database connection variables.
require_once("connect.php");
// simple function to take a query, run it against the data warehouse
// and return a multi-indexed array of the results, if any.
// if there are no results, the function returns 0.
function queryToArray($query){
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
if($numRows > 0){
while($row = mssql_fetch_assoc($result)){
$arrayOfCustomerInformation[] = $row;
}
return $arrayOfCustomerInformation;
}
else {
return 0;
}
}
//generic query to pull top 100 values from the wh_account table
//where the account_type_id = 7 (Vendor)
// and is_active = 1 (Currently Active)
$query = "select
top(100)*
from
wh_account
where
account_type_id = '7' AND
is_active = '1'
";
//create an array of values that are returned by the query
$myVendorArray = queryToArray($query);
//If there are results from the query, print them out to the
//screen.
// Brief explanation of this array:
// $myVendorArray stores a multi-indexed array of accounts.
// each index ($k) is a unique customer account.
// each index ($k) has an associative array of key, value pairs
// that can be referenced by name like this
//
// $myCustomerArray[$k]["address_1"]
//
//NOTE: These may change over time!
/*
[account_id] => 0
[owner_resource_id] => 4
[create_time] => May 16 2002 6:56AM
[external_id] =>
[account_name] => BestISP
[directory_account_id] => 0
[address_1] => 987 Service Lane
[address_2] =>
[city] => Fakerton
[state] => VA
[zip_code] => 12345
[country] =>
[phone_number] => (555)555-1984
[alternate_phone_1] =>
[alternate_phone_2] =>
[fax_number] =>
[web_url] => http://www.bestISP.com
[account_type_id] => 7
[key_account_icon_id] =>
[territory_id] =>
[market_segment_id] => 29682845
[competitor_id] =>
[parent_account_id] =>
[stock_symbol] =>
[stock_market] =>
[sic_code] =>
[asset_value] =>
[last_activity_time] => Sep 26 2009 3:31PM
[external_accounting_id] =>
[is_active] => 1
[is_costed_client] => 0
[is_tax_exempt] => 0
[uses_parent_account_contracts] => 0
*/
echo "<hr>";
if($myVendorArray != 0){
echo "<b>".count($myVendorArray)." Active Vendors</b>\n<br/>";
for($k=0;$k<count($myVendorArray);$k++){
echo " ".$myVendorArray[$k]["account_name"]." - "
.$myVendorArray[$k]["phone_number"]." - "
.$myVendorArray[$k]["web_url"]."\n<br/>";
}
}
echo "<hr>";
//to quickly see all values returned, use the print_r function.
//(commented out.)
// echo "<pre>\n";
// print_r($myVendorArray);
// echo "</pre>\n";
?>
One of the more powerful components of Autotask is how it handles Assets (Installed Products or Configuration Items.)
In this example, we will display a list of assets and some key information about each.
It will appear like this.
| Vendor | Vendor Phone | Reference Title | Serial Number | Warranty Exp Date | Notes | Product ID |
| TWC | 18005551234 | Primary Internet | 26hcgs123456 | Sep 1 2011 | No Notes. | 123456 |
| TWC | 18005551234 | Primary Internet | 789ad7458 | Jan 1 2010 | Need to renew | 123459 |
| TWC | 18005551234 | Primary Internet | 12457898 | Oct 15 2010 | No Notes. | 123421 |
listAssets.php - save as listAssets.php
For simplicity in these examples, all files are 'self-contained' and do not reference common includes - aside from the previously mentioned 'connect.php' file.
<?php
//Include connect.php as it stores all remote database connection variables.
require_once("connect.php");
// simple function to take a query, run it against the data warehouse
// and return a multi-indexed array of the results, if any.
// if there are no results, the function returns 0.
function queryToArray($query){
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
if($numRows > 0){
while($row = mssql_fetch_assoc($result)){
$arrayOfCustomerInformation[] = $row;
}
return $arrayOfCustomerInformation;
}
else {
return 0;
}
}
//generic query to pull top 100 values from the Installed Product table
// where is_active = 1 (Currently Active)
// in this query, we are JOINING with the account table to provide a
// meaningful link between assets and accounts. We are using a LEFT
// Join to show any assets without a 'Vendor Name'
// (to show only assets with vendor names, change LEFT to INNER
//This query shows all assets assigned to the '0' account.
// (your internal Autotask account)
$query = "select
top(100)
wh_installed_product.reference_title,
wh_installed_product.serial_number,
wh_installed_product.installed_product_id,
wh_installed_product.warranty_expiration_date,
wh_installed_product.notes,
wh_installed_product.vendor_name,
wh_installed_product.account_id,
wh_account.account_name,
wh_account.phone_number,
wh_account.web_url
from
wh_installed_product LEFT JOIN
wh_account ON wh_installed_product.vendor_name
= wh_account.account_name
where
wh_installed_product.is_active = '1' AND
wh_installed_product.account_id = '0'
order by
wh_installed_product.warranty_expiration_date
";
/*
//uncomment this query to show All Assets for All accounts.
$query = "select
top(100)
wh_installed_product.reference_title,
wh_installed_product.serial_number,
wh_installed_product.installed_product_id,
wh_installed_product.warranty_expiration_date,
wh_installed_product.notes,
wh_installed_product.vendor_name,
wh_installed_product.account_id,
wh_account.account_name,
wh_account.phone_number,
wh_account.web_url
from
wh_installed_product LEFT JOIN
wh_account ON wh_installed_product.vendor_name
= wh_account.account_name
where
wh_installed_product.is_active = '1'
order by
wh_installed_product.warranty_expiration_date
";
*/
//create an array of values that are returned by the query
$myAssetArray = queryToArray($query);
//If there are results from the query, print them out to the
//screen.
// Brief explanation of this array:
// $myAssetArray stores a multi-indexed array of accounts.
// each index ($k) is a unique customer asset / Installed Product.
// each index ($k) has an associative array of key, value pairs
// that can be referenced by name like this
//
// $myAssetArray[$k]["reference_title"]
//
//NOTE: These may change over time!
/*
[installed_product_id] => 29683402
[product_id] => 29683401
[account_id] => 29683321
[start_date] => Mar 27 2009 12:00AM
[warranty_expiration_date] => Mar 27 2010 12:00AM
[serial_number] => 26hcgs1234567
[reference_number] =>
[reference_title] => Guest Wireless Internet
[number_of_users] => 0.0000
[hourly_cost] => 0.0000
[monthly_cost] => 0.0000
[daily_cost] => 0.0000
[per_use_cost] => 0.0000
[setup_fee] => 0.0000
[account_link] =>
[notes] =>
[project_cost_id] =>
[quote_item_id] =>
[is_active] => 1
[create_time] => Mar 27 2009 11:32PM
[installed_product_type] =>
[location] =>
[contact_first_name] =>
[contact_last_name] =>
[vendor_name] =>
[contract_id] =>
[service_id] =>
[service_bundle_id] =>
[installed_by_resource_id] => 29682885
[is_swapped_out] => 0
[inventory_transfer_id] =>
*/
echo "<hr>";
if($myAssetArray != 0){
echo "<b>".count($myAssetArray)." Active Assets</b>\n<br/>";
echo "<table style=\"border:1px black solid;
border-collapse:collapse;\">\n";
echo "<tr><td>Vendor</td>".
"<td>Vendor Phone</td>".
"<td>Reference Title</td>".
"<td>Serial Number</td>".
"<td>Warranty Exp Date</td>".
"<td>Notes</td>".
"<td>Product ID</td>".
"</tr>";
for($k=0;$k<count($myAssetArray);$k++){
echo "<tr> ".
"<td style=\"border:1px black solid;\">".
$myAssetArray[$k]["account_name"]."</td>".
"<td style=\"border:1px black solid;\">".
$myAssetArray[$k]["phone_number"] ."</td>".
"<td style=\"border:1px black solid;\">".
$myAssetArray[$k]["reference_title"]."</td>".
"<td style=\"border:1px black solid;\">".
$myAssetArray[$k]["serial_number"] ."</td>".
"<td style=\"border:1px black solid;\">".
$myAssetArray[$k]["warranty_expiration_date"].
"</td>".
"<td style=\"border:1px black solid;\">".
$myAssetArray[$k]["notes"] ."</td>".
"<td style=\"border:1px black solid;\">".
$myAssetArray[$k]["installed_product_id"] ."</td>".
"</tr>\n<br/>";
}
echo "</table>\n";
}
else{
echo "There were 0 results returned.
There are no assets associated with this account.\n<br/>";
}
echo "<hr>";
//to quickly see all values returned, use the print_r function.
//(commented out.)
echo "<pre>\n";
print_r($myAssetArray);
echo "</pre>\n";
?>
In this example, we will combine the previous steps to display a list of customers, with each of their active Assets and related Vendor Contact Information.
It will appear like this.
You can copy and paste the code below to a new file called 'listVendors.php' - or download the file here.
listAssetsByCust.php - save as listAssetsByCust.php
<?php
//Include connect.php as it stores all remote database connection variables.
require_once("connect.php");
// simple function to take a query, run it against the data warehouse
// and return a multi-indexed array of the results, if any.
// if there are no results, the function returns 0.
function queryToArray($query){
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
if($numRows > 0){
while($row = mssql_fetch_assoc($result)){
$arrayOfCustomerInformation[] = $row;
}
return $arrayOfCustomerInformation;
}
else {
return 0;
}
}
?>
<html>
<head><title>Assets per Customer</title></head>
<STYLE type="text/css">
html{
background:
transparent url(img/background.gif) repeat scroll 0 0;
}
body{
background:#fff;
color:#333;
margin:2em auto 0 auto;
width:850px;
padding:1em 2em;
border:1px solid #dfdfdf;
}
table { border: 1px solid #aaa;
border-collapse: collapse;
padding: 4px;
}
td { border: 1px solid;
padding: 6px;}
</style>
<body>
<?php
echo "<h2>List of Assets per customer</h2>";
//Part 1: Obtain list of Active Customers.
$query = "select
top(100)*
from
wh_account
where
account_type_id = '1' AND
is_active = '1'
";
$myCustomerArray = queryToArray($query);
//Part 2: Per Customer, enumerate All assets
//generic query to pull top 100 values from the Installed Product table
// where is_active = 1 (Currently Active)
// in this query, we are JOINING with the account table to provide a
// meaningful link between assets and accounts. We are using a LEFT
// Join to show any assets without a 'Vendor Name'
// (to show only assets with vendor names, change LEFT to INNER
for($i = 0; $i<count($myCustomerArray); $i++){
echo "".$myCustomerArray[$i]["account_name"] ."\n<br/>";
echo "P:".$myCustomerArray[$i]["phone_number"] ."\n<br/>";
echo "W:<a href=\"".$myCustomerArray[$i]["web_url"]."\"
target=\"_blank\">".$myCustomerArray[$i]["web_url"] .
"</a>\n<br/>";
//This query shows all assets assigned to the '0' account.
// (your internal Autotask account)
$query = "select
top(100)
wh_installed_product.reference_title,
wh_installed_product.serial_number,
wh_installed_product.installed_product_id,
wh_installed_product.warranty_expiration_date,
wh_installed_product.notes,
wh_installed_product.vendor_name,
wh_installed_product.account_id,
wh_account.account_name,
wh_account.phone_number,
wh_account.web_url
from
wh_installed_product LEFT JOIN
wh_account ON wh_installed_product.vendor_name
= wh_account.account_name
where
wh_installed_product.is_active = '1' AND
wh_installed_product.account_id = '".
$myCustomerArray[$i]["account_id"]."'
order by
wh_installed_product.warranty_expiration_date
";
//create an array of values that are returned by the query
$myAssetArray = queryToArray($query);
//If there are results from the query, print them out to the
//screen.
echo "<br/>";
if($myAssetArray != 0){
echo "<b>".count($myAssetArray)." Active Asset(s)</b>\n<br/>";
echo "<table>\n";
echo "<tr><td>Vendor</td>".
"<td>Vendor Phone</td>".
"<td>Reference Title</td>".
"<td>Serial Number</td>".
"<td>Warranty Exp Date</td>".
"<td>Notes</td>".
"<td>Product ID</td>".
"<td>Product UDF</td>".
"</tr>";
for($k=0;$k<count($myAssetArray);$k++){
echo "<tr> ".
"<td>".
$myAssetArray[$k]["account_name"]."</td>".
"<td>".
$myAssetArray[$k]["phone_number"] ."</td>".
"<td>".
$myAssetArray[$k]["reference_title"]."</td>".
"<td>".
$myAssetArray[$k]["serial_number"] ."</td>".
"<td>".
$myAssetArray[$k]["warranty_expiration_date"].
"</td>".
"<td>".
$myAssetArray[$k]["notes"] ."</td>".
"<td>".
$myAssetArray[$k]["installed_product_id"] ."</td>";
//NOTE: the values listed in the 'CAST' parends below must match the names
//you used for the UDF in Autotask. Replace spaces with '_'
//Also- list types must append '_visible_value' to the end of the variable.
$query = "select
CAST(circuit_id as TEXT) as circuit_id,
CAST(circuit_type_visible_value as TEXT) as circuit_type,
CAST(download_speed as TEXT) as download_speed,
CAST(upload_speed as TEXT) as upload_speed,
CAST(public_ip_address as TEXT) as public_ip_address,
CAST(public_subnet_mask as TEXT) as public_subnet_mask,
CAST(public_default_gateway as TEXT) as public_default_gateway,
CAST(useable_public_range as TEXT) as useable_public_range
from
wh_installed_product_udf
where
installed_product_id = '".
$myAssetArray[$k]["installed_product_id"]."'
";
$myUDFArray = queryToArray($query);
echo "<td style=\"border:1px black solid;\"><pre>\n";
print_r($myUDFArray);
echo "</pre>\n</td>";
echo "</tr>";
}
echo "</table>\n";
}
else{
echo "There were 0 results returned.
There are no assets associated with this account.\n<br/>";
}
echo "<hr>";
//to quickly see all values returned, use the print_r function.
//(commented out.)
// echo "<pre>\n";
// print_r($myAssetArray);
// echo "</pre>\n";
}
?>
</body>
</html>
DWAccount.class - save as DWAccount.class