Adding Extended Attributes to Resource Assignments
Contents
[
Hide
Show
]The extended attributes can be added to resource assignments the same way the tasks and resources are added. Aspose.Tasks for C++ 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
1// Create new project
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Blank2010.mpp");
3
4// Add new task and resource
5System::SharedPtr<Task> task1 = project->get_RootTask()->get_Children()->Add(u"Task");
6System::SharedPtr<Resource> rsc1 = project->get_Resources()->Add(u"Rsc");
7
8// Assign the resource to the desired task
9System::SharedPtr<ResourceAssignment> assignment = project->get_ResourceAssignments()->Add(task1, rsc1);
10
11// Custom attributes which is visible in "Resource Usage" view can be created with ExtendedAttributeDefinition.CreateResourceDefinition method.
12
13{
14 System::SharedPtr<ExtendedAttributeDefinition> resCostAttributeDefinition = ExtendedAttributeDefinition::CreateResourceDefinition(Aspose::Tasks::CustomFieldType::Cost, Aspose::Tasks::ExtendedAttributeResource::Cost5, u"My cost");
15
16 project->get_ExtendedAttributes()->Add(resCostAttributeDefinition);
17
18 auto value = resCostAttributeDefinition->CreateExtendedAttribute();
19
20 // The type of the attribute is "Cost", so we need to use "NumericValue" property.
21 value->set_NumericValue(1500);
22
23 assignment->get_ExtendedAttributes()->Add(value);
24}
25
26// Custom attributes which is visible in "Task Usage" view can be created with ExtendedAttributeDefinition.CreateTaskDefinition method
27
28{
29 System::SharedPtr<ExtendedAttributeDefinition> taskCostAttributeDefinition = ExtendedAttributeDefinition::CreateTaskDefinition(Aspose::Tasks::CustomFieldType::Cost, Aspose::Tasks::ExtendedAttributeTask::Cost5, u"My cost for task");
30
31 project->get_ExtendedAttributes()->Add(taskCostAttributeDefinition);
32
33 auto value = taskCostAttributeDefinition->CreateExtendedAttribute();
34
35 // The type of the attribute is "Cost", so we need to use "NumericValue" property.
36 value->set_NumericValue(2300);
37
38 assignment->get_ExtendedAttributes()->Add(value);
39}
40
41project->Save(dataDir + u"AddExtendedAttributesToResourceAssignment_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
Adding Lookup Extended Attributes to Resource Assignment
1// Create new project
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Blank2010.mpp");
3
4// Assign resource "1 TRG: Trade Group" to the "TASK 1" by creating a ResourceAssignment object.
5System::SharedPtr<Resource> resource = project->get_Resources()->GetById(1);
6System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->GetById(1);
7
8System::SharedPtr<ResourceAssignment> assignment = project->get_ResourceAssignments()->Add(task, resource);
9
10// Create custom attribute definition with lookup.
11System::SharedPtr<ExtendedAttributeDefinition> resCostAttr = ExtendedAttributeDefinition::CreateLookupResourceDefinition(Aspose::Tasks::CustomFieldType::Cost, Aspose::Tasks::ExtendedAttributeResource::Cost5, u"My lookup resource cost");
12project->get_ExtendedAttributes()->Add(resCostAttr);
13
14auto value1 = [&]{ auto tmp_0 = System::MakeObject<Value>(); tmp_0->set_NumericValue(1500); tmp_0->set_Description(u"Val 1"); tmp_0->set_Id(1); tmp_0->set_Val(u"1500"); return tmp_0; }();
15
16resCostAttr->AddLookupValue(value1);
17
18resCostAttr->AddLookupValue([&]{ auto tmp_1 = System::MakeObject<Value>(); tmp_1->set_NumericValue(2500); tmp_1->set_Description(u"Val 2"); tmp_1->set_Id(2); return tmp_1; }());
19
20// This value can be seen in "Resource usage" view of MS Project.
21auto attributeValue = resCostAttr->CreateExtendedAttribute(value1);
22assignment->get_ExtendedAttributes()->Add(attributeValue);
23
24// Create custom attribute definition with lookup.
25System::SharedPtr<ExtendedAttributeDefinition> taskCostAttr = ExtendedAttributeDefinition::CreateLookupTaskDefinition(Aspose::Tasks::ExtendedAttributeTask::Cost4, u"My lookup task cost");
26
27project->get_ExtendedAttributes()->Add(taskCostAttr);
28
29auto taskLookupValue1 = [&]{ auto tmp_2 = System::MakeObject<Value>(); tmp_2->set_NumericValue(18); tmp_2->set_Description(u"Task val 1"); tmp_2->set_Id(3); tmp_2->set_Val(u"18"); return tmp_2; }();
30taskCostAttr->AddLookupValue(taskLookupValue1);
31
32resCostAttr->AddLookupValue([&]{ auto tmp_3 = System::MakeObject<Value>(); tmp_3->set_NumericValue(30); tmp_3->set_Description(u"Task val 2"); tmp_3->set_Id(4); return tmp_3; }());
33
34// This value can be seen in "Task usage" view of MS Project.
35assignment->get_ExtendedAttributes()->Add(taskCostAttr->CreateExtendedAttribute(taskLookupValue1));
36
37project->Save(dataDir + u"AddExtendedAttributesToRAWithLookUp_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);