To learn more about Tempo products, please visit our Help Center. For support, see our Support Portal.
Dynamic work attributes in Tempo Timesheets for Data Center
Question | How do I create a dynamic work attribute in Tempo Timesheets for Data Center |
---|---|
Answer | Work attributes can be added as additional fields to the worklog dialog screen within Tempo Timesheets (required permission: Tempo Administrator). Work attributes can be added within the Tempo report engine and are included in the Excel output reports as well. First, create the worklog attribute field from the Tempo Administration section. Select the type "Dynamic Dropdown": Click the "Configure API URL (for dropdown values)" and enter the path to your script. Add the user parameter ("/{author}") to the script url to pass the user key to it.
$callback= $_GET['callback'];
echo $callback;
$url = $_SERVER['PHP_SELF'];
$path = parse_url($url, PHP_URL_PATH);
$pos = strpos ( $path , '/' ,1 );
$len = strlen ( $path );
$parameter = substr ( $path , $pos+1, $len-$pos);
$datetoday = date('Y-m-d', time());
$url = "http://localhost:8080/rest/tempo-teams/2/teammember/".$parameter."/memberships?from=".$datetoday."&to=".$datetoday;
$username = 'username';$password = 'password';
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$jsonData = (json_decode($output, true));
$teams = count($jsonData);
Finally the script needs to parse the data in JSON to be readable by the Tempo interpreter. The format need to be similar to the following: (
{"values":[
{"key":"0100","value":"This is option ONE"},
{"key":"0200","value":"And here is option TWO"}
]
}
)
(
{"values": [
<?php$i = 1; foreach ($jsonData as $team) { ?>
{"key":"<?php echo $team['team']['id'];?>",
"value":"<?php echo $team['team']['name'];?> "
<?phpif ($teams === $i) {?> }<?php }
else {?> },
<?php } $i++;}?>
]
}
)
As a side note: the value will be preselected when there is only one option available AND the work attribute has been made required. |