Learning to Retrieve a Specific Extended Attribute by Index

In this tutorial, you’ll learn how to retrieve detailed information about a specific extended attribute by its index from MS Project files using the Aspose.Tasks Cloud API. This skill allows you to access all properties and settings of individual custom fields, which is essential for applications that need to interpret or modify project metadata.

Learning Objectives

By the end of this tutorial, you will be able to:

  • Make API calls to retrieve a specific extended attribute by index
  • Understand the structure and properties of individual extended attributes
  • Interpret complex extended attribute properties like value lists and calculation types
  • Implement the functionality in your preferred programming language
  • Process and utilize the detailed extended attribute information

Prerequisites

Before starting this tutorial, make sure you have:

  1. Completed the previous tutorial on Getting Extended Attributes Information
  2. An Aspose Cloud account
  3. Valid Aspose.Tasks Cloud API credentials (Client ID and Client Secret)
  4. A MS Project file with extended attributes stored in your Aspose Cloud Storage

Understanding Extended Attribute Details

An individual extended attribute contains detailed information such as:

  • Field type (Text, Number, Date, etc.)
  • Custom field properties (alias, GUID, calculation type, etc.)
  • Value list definitions for lookup fields
  • Formulas for calculated fields
  • Default values and constraints

Accessing this detailed information is crucial for applications that need to interpret or modify project metadata.

Tutorial Steps

Step 1: Set Up Authentication

First, let’s set up authentication to access the Aspose.Tasks Cloud API:

Using cURL

# First, get the JWT token
curl -v "https://api.aspose.cloud/connect/token" -X POST -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json"

# Store the received access_token for subsequent requests

Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your actual credentials.

Step 2: Make the API Call to Get a Specific Extended Attribute

Now let’s retrieve a specific extended attribute by its index:

Using cURL

curl -X GET "https://api.aspose.cloud/v3.0/tasks/Home%20move%20plan.mpp/extendedAttributes/1" \
     -H "accept: application/json" \
     -H "authorization: Bearer YOUR_ACCESS_TOKEN"

Replace YOUR_ACCESS_TOKEN with the token received in Step 1, and adjust the index as needed.

Step 3: Implement in PHP

Let’s see how to implement this in PHP:

<?php
// Tutorial Code Example: Getting a Specific Extended Attribute in PHP
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization
$config = new \Aspose\Tasks\Configuration();
$config->setClientId('YOUR_CLIENT_ID');
$config->setClientSecret('YOUR_CLIENT_SECRET');

// Initialize API client
$apiClient = new \Aspose\Tasks\ApiClient($config);
$tasksApi = new \Aspose\Tasks\Api\TasksApi($apiClient);

try {
    // Specify the project file name
    $fileName = 'Home move plan.mpp';
    
    // Specify the index of the extended attribute to retrieve
    $index = 1;
    
    // Call the API to get the extended attribute
    $result = $tasksApi->getExtendedAttributeByIndex($fileName, $index);
    
    // Process and display the result
    echo "Status: " . $result->getStatus() . "\n";
    
    // Access the extended attribute details
    $extAttr = $result->getExtendedAttribute();
    
    echo "Field ID: " . $extAttr->getFieldId() . "\n";
    echo "Field Name: " . $extAttr->getFieldName() . "\n";
    echo "CF Type: " . $extAttr->getCfType() . "\n";
    echo "Alias: " . $extAttr->getAlias() . "\n";
    echo "User Defined: " . ($extAttr->getUserDef() ? 'Yes' : 'No') . "\n";
    
    // Display calculation information if available
    echo "Calculation Type: " . $extAttr->getCalculationType() . "\n";
    if ($extAttr->getFormula()) {
        echo "Formula: " . $extAttr->getFormula() . "\n";
    }
    
    // Display value list if available
    $valueList = $extAttr->getValueList();
    if ($valueList && count($valueList) > 0) {
        echo "\nValue List:\n";
        foreach ($valueList as $value) {
            echo "ID: " . $value->getId() . "\n";
            echo "Value: " . $value->getVal() . "\n";
            echo "Description: " . $value->getDescription() . "\n";
            echo "---\n";
        }
    }
    
} catch (Exception $e) {
    echo "Exception when calling TasksApi->getExtendedAttributeByIndex: " . $e->getMessage() . "\n";
    echo "HTTP response body: " . $e->getResponseBody() . "\n";
}
?>

Step 4: Process and Use the Response

The API response provides detailed information about the specified extended attribute. Let’s examine a sample response:

{
  "code": 0,
  "status": "OK",
  "extendedAttribute": {
    "fieldId": "188743731",
    "fieldName": "Text1",
    "cfType": "Text",
    "guid": "11111111-1111-1111-1111-111111111111",
    "elementType": "Task",
    "maxMultiValues": 0,
    "userDef": true,
    "alias": "Custom Category",
    "secondaryPid": "",
    "autoRollDown": false,
    "defaultGuid": "",
    "lookupUid": "",
    "phoneticsAlias": "",
    "rollupType": "Null",
    "calculationType": "Lookup",
    "formula": "",
    "restrictValues": true,
    "valuelistSortOrder": 0,
    "appendNewValues": true,
    "default": "",
    "valueList": [
      {
        "id": 1,
        "val": "High Priority",
        "dateTimeValue": "0001-01-01T00:00:00",
        "durationValue": 0,
        "description": "Tasks that must be completed first",
        "phonetic": ""
      },
      {
        "id": 2,
        "val": "Medium Priority",
        "dateTimeValue": "0001-01-01T00:00:00",
        "durationValue": 0,
        "description": "Standard priority tasks",
        "phonetic": ""
      },
      {
        "id": 3,
        "val": "Low Priority",
        "dateTimeValue": "0001-01-01T00:00:00",
        "durationValue": 0,
        "description": "Tasks that can be delayed if needed",
        "phonetic": ""
      }
    ],
    "secondaryGuid": ""
  }
}

Step 5: Understanding Key Properties

Let’s understand some of the key properties in the response:

  1. fieldId: The internal ID used by MS Project
  2. fieldName: The display name in MS Project (e.g., “Text1”, “Cost1”)
  3. cfType: The data type (Text, Number, Cost, Date, Duration, Flag, etc.)
  4. elementType: Whether this applies to Task, Resource, or Assignment
  5. alias: The user-friendly name assigned to this field
  6. calculationType: How values are computed (None, Lookup, Formula, etc.)
  7. restrictValues: Whether users are limited to predefined values
  8. valueList: Collection of predefined values for lookup fields

Step 6: Working with Different Types of Extended Attributes

Depending on the cfType and calculationType, extended attributes can behave differently:

Text Fields

  • Can store arbitrary text or be restricted to a predefined list
  • May have phonetic information for languages like Japanese

Number/Cost Fields

  • May have formulas that calculate values automatically
  • Often have specific formatting for display purposes

Date Fields

  • Store date/time values
  • May have default values or constraints

Lookup Fields

  • Have a predefined list of values to choose from
  • Often used for categorization or classification

Try It Yourself

Now that you understand how to access a specific extended attribute, try implementing this feature in your own application:

  1. Set up authentication with your Aspose Cloud credentials
  2. Retrieve all extended attributes using the previous tutorial’s method
  3. Select a specific extended attribute index
  4. Make the API call to retrieve detailed information for that index
  5. Process and display the detailed information based on its type

Troubleshooting Tips

  • 404 Not Found: Verify that the specified file exists in your storage
  • Invalid Index: Ensure that the extended attribute index you’re requesting actually exists in the project
  • Type-Specific Issues: Different attribute types have different properties; check which ones are applicable

What You’ve Learned

In this tutorial, you’ve learned:

  • How to retrieve a specific extended attribute by its index
  • The structure and properties of individual extended attributes
  • How to implement this functionality in PHP
  • How to process and utilize the detailed extended attribute information
  • The significance of various properties based on the attribute type

Further Practice

To strengthen your understanding, try these exercises:

  1. Create a function that retrieves all extended attributes and then gets detailed information for each one
  2. Build a tool that displays extended attributes grouped by their type
  3. Create a visualization of lookup fields showing their value lists
  4. Implement filtering functionality to find tasks that use specific extended attribute values

Next Tutorial

Ready to learn more? Continue to the next tutorial: How to Delete a Project Extended Attribute to learn how to remove extended attributes from your projects.

Useful Resources

Have questions about this tutorial? Feel free to post them on our support forum.