Adding Extended Attributes to Resource Assignments
Contents
[
Hide
Show
]Like Tasks and Resources, Extended Attributes can be added to Resource Assignments as well. Aspose.Tasks for Java API lets you add Extended Attributes to Resource Assignments. Extended Attributes can be added to Resource Assignments as plain as well as Lookup attributes.
Adding Extended Attributes to Resource Assignment
1Project project = new Project(dataDir + "Blank2010.mpp");
2
3// Add new task and resource
4Task task1 = project.getRootTask().getChildren().add("Task");
5Resource rsc1 = project.getResources().add("Rsc");
6
7// Assign the resource desired task
8ResourceAssignment assn = project.getResourceAssignments().add(task1, rsc1);
9
10ResourceAssignment assignment = project.getResourceAssignments().toList().get(0);
11
12// Custom attributes which is visible in "Resource Usage" view can be created
13// with ExtendedAttributeDefinition.CreateResourceDefinition method.
14ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition
15 .createResourceDefinition(CustomFieldType.Cost, ExtendedAttributeResource.Cost5, "My cost");
16
17project.getExtendedAttributes().add(resCostAttr);
18
19ExtendedAttribute value = resCostAttr.createExtendedAttribute();
20value.setNumericValue(BigDecimal.valueOf(1500));
21assignment.getExtendedAttributes().add(value);
22
23// Custom attributes which is visible in "Task Usage" view can be created with
24// ExtendedAttributeDefinition.CreateTaskDefinition method
25ExtendedAttributeDefinition resCostAttr2 = ExtendedAttributeDefinition
26 .createTaskDefinition(CustomFieldType.Cost, ExtendedAttributeTask.Cost5, "My cost for task");
27
28project.getExtendedAttributes().add(resCostAttr2);
29
30value = resCostAttr2.createExtendedAttribute();
31value.setNumericValue(BigDecimal.valueOf(2300));
32
33assignment.getExtendedAttributes().add(value);
34
35project.save(dataDir + "AddExtendedAttributesToResourceAssignment_out.mpp", SaveFileFormat.MPP);
Adding Lookup Extended Attributes to Resource Assignment
1Project project = new Project(dataDir + "Blank2010.mpp");
2
3ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition.createLookupResourceDefinition(
4 CustomFieldType.Cost, ExtendedAttributeResource.Cost5, "My lookup cost");
5
6Value value1 = new Value();
7value1.setNumericValue(BigDecimal.valueOf(1500));
8value1.setDescription("Val 1");
9value1.setId(1);
10value1.setVal("1500");
11
12resCostAttr.addLookupValue(value1);
13
14Value value2 = new Value();
15value1.setNumericValue(BigDecimal.valueOf(2500));
16value1.setDescription("Val 2");
17value1.setId(2);
18
19resCostAttr.addLookupValue(value2);
20
21project.getExtendedAttributes().add(resCostAttr);
22
23ExtendedAttribute value = resCostAttr.createExtendedAttribute(value1);
24value.setNumericValue(BigDecimal.valueOf(1500));
25project.save(dataDir + "AddExtendedAttributesToRAWithLookUp_out.mpp", SaveFileFormat.MPP);