Working with Extended Attributes of a Project

Microsoft Project has an extensive XML data interchange schema that exchanging information between applications - and programming with project files - easier. The schema allows you to add extended attributes to tasks, resources and assignments. This article shows how to assign an extended attribute to a resource assignment with Aspose.Tasks.

Setting Extended Attributes The ExtendedAttribute property exposed by the ResourceAssignment class can be used to manage the extended attributes of an assignment. This property reads or writes a List of the ExtendedAttribute objects to deal with a resource’s extended attributes. The ExtendedAttribute object further exposes the relevant properties.

The following example shows setting the extended attributes of a resource.

 1// The path to the documents directory.
 2String dataDir = Utils.getDataDir(ExtendedAttributes.class);
 3
 4Project prj = new Project(dataDir + "project5.mpp");
 5ExtendedAttributeDefinitionCollection eads = prj.getExtendedAttributes();
 6
 7// Create extended attribute definition
 8ExtendedAttributeDefinition attributeDefinition = ExtendedAttributeDefinition
 9        .createTaskDefinition(CustomFieldType.Start, ExtendedAttributeTask.Start7, "Start 7");
10prj.getExtendedAttributes().add(attributeDefinition);
11
12eads.add(attributeDefinition);
13
14// Get zero index task
15Task tsk = prj.getRootTask().getChildren().getById(1);
16ExtendedAttributeCollection eas = tsk.getExtendedAttributes();
17
18// Add extended attribute
19ExtendedAttribute ea = attributeDefinition.createExtendedAttribute();
20ea.setFieldId(attributeDefinition.getFieldId());
21
22Date date = new Date();
23ea.setDateValue(date);
24
25eas.add(ea);
26
27prj.save(dataDir + "Project5.xml", SaveFileFormat.XML);
28
29// Display result of conversion.
30System.out.println("Process completed Successfully");
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.