Document toolboxDocument toolbox

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.
Dynamic work attributes are special in that you define the list items in an external service that connects to Tempo Timesheets. Additionally Tempo can pass several parameters from the worklog dialog screen (Jira issue key, the user key and the Tempo account key) to the script in order to make the available work attributes dependent on the selected value within the worklog dialog screen. In the example below, we show you how you can create a dynamic work attribute that will pull all Tempo Teams the user (who logs the time) is a member of as possible options to select. Follow the steps below to set up a dynamic work attribute.

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"} ] } )


We use our script to create the JSON data by looping through the returned values from the API call.

( {"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++;}?> ] } )


That's it! When we look into our worklog dialog screen we should see the work attribute be populated by all team members the user is member of:

As a side note: the value will be preselected when there is only one option available AND the work attribute has been made required.