Extended Attributes to Resource Assignments using Aspose.Tasks for Java 18.6

Share on FacebookTweet about this on TwitterShare on LinkedIn

We are pleased to announce the release of Aspose.Tasks for Java 18.6. This release introduces a new feature of writing extended attributes information to resource assignments similar to tasks and resources. It also improves the overall API functionality by fixing issues reported with the previous version of the API. For a detailed note on what is new and fixed, please visit the release notes section of API documentation.

Adding Extended Attributes to Resource Assignments

Aspose.Tasks API already had the capability to add extended attributes to tasks and resources in a project. This month’s release introduces the capability to add extended attributes information to resource assignments as well. Extended Attributes can be added to resource assignments as plain as well as lookup values. Following examples show adding these two type of extended attributes to the project.

Adding Extended Attribute

Project project = new Project(dataDir + "Blank2010.mpp");

// Add new task and resource
Task task1 = project.getRootTask().getChildren().add("Task");
Resource rsc1 = project.getResources().add("Rsc");

// Assign the resource desired task
ResourceAssignment assn = project.getResourceAssignments().add(task1, rsc1);

ResourceAssignment assignment = project.getResourceAssignments().get(0);

// Custom attributes which is visible in "Resource Usage" view can be created with ExtendedAttributeDefinition.CreateResourceDefinition method.
ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition.createResourceDefinition(
    CustomFieldType.Cost,
    ExtendedAttributeResource.Cost5,
    "My cost");

   project.getExtendedAttributes().add(resCostAttr);

   ExtendedAttribute value = resCostAttr.createExtendedAttribute();
   value.setValue("1500");

   assignment.getExtendedAttributes().add(value);

   // Custom attributes which is visible in "Task Usage" view can be created with ExtendedAttributeDefinition.CreateTaskDefinition method
   ExtendedAttributeDefinition resCostAttr2 = ExtendedAttributeDefinition.createTaskDefinition(
       CustomFieldType.Cost,
       ExtendedAttributeTask.Cost5,
       "My cost for task");

   project.getExtendedAttributes().add(resCostAttr2);

   value = resCostAttr2.createExtendedAttribute();
   value.setValue("2300");

   assignment.getExtendedAttributes().add(value);

project.save(dataDir + "AddExtendedAttributesToResourceAssignment_out.mpp", SaveFileFormat.MPP);

Adding Extended Attribute as Lookup Value

Project project = new Project(dataDir + "Blank2010.mpp");

ResourceAssignment assignment = project.getResourceAssignments().get(0);

ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition.createLookupResourceDefinition(
				                                      CustomFieldType.Cost,
		                                                      ExtendedAttributeResource.Cost5,
				                                      "My lookup cost");

Value value1 = new Value();
value1.setNumberValue(1500);
value1.setDescription("Val 1");
value1.setId(1);
value1.setVal("1500");

resCostAttr.addLookupValue(value1);
		
Value value2 = new Value();
value1.setNumberValue(2500);
value1.setDescription("Val 2");
value1.setId(2);
		 
resCostAttr.addLookupValue(value2);
		 
project.getExtendedAttributes().add(resCostAttr);
		
ExtendedAttribute value = resCostAttr.createExtendedAttribute(value1);
value.setValue("1500");
project.save(dataDir + "AddExtendedAttributesToRAWithLookUp_out.mpp", SaveFileFormat.MPP);

API Resources

You may visit the following API resources for getting started and working with the API.

  • Product Documentation – Provides complete information about system requirements, installation, Programmer’s Guide, Technical articles and API Changes
  • API Reference Guide – Provides information about the product namespaces, classes and methods
  • GitHub Examples – Ready to download and execute examples of the API
  • Forum Support – Post your queries/inquiries on Aspose.Tasks forum to get support from our technical support team.