Update Outline Code Definitions and Values

Aspose.Tasks for Java provides the facility to add new outline code attributes to an existing Microsoft Project MPP file and save it back.

Updating Outline Code Definitions and Values

The following code sample defines new outline codes and sets its various fields. The outlines codes and values are then added to the project outline codes and the updated data is saved back to MPP file. The steps involved in this activity are:

  1. Create an instance of Project Reader.
  2. Read the source MPP file.
  3. Define new OutlineValue objects and set the parameters.
  4. Add the outline codes to the project’s codes.
  5. Save the updated project data back to the MPP file.
 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir(WriteUpdatedOutlineCode.class);
 4
 5String newFile = "New Project 2013.mpp";
 6
 7String resultFile = "OutputMPP.mpp";
 8
 9Project project = new Project(dataDir + newFile);
10ArrayList projectOutlCodes = new ArrayList();
11
12OutlineCodeDefinition code1 = new OutlineCodeDefinition();
13code1.setAlias("New task outline code1");
14code1.setFieldId(String.valueOf((int) ExtendedAttributeTask.OutlineCode1));
15code1.setFieldName("Outline Code1");
16
17OutlineMask mask = new OutlineMask();
18mask.setSeparator("+");
19mask.setLevel(1);
20mask.setType(MaskType.Numbers);
21
22code1.getMasks().add(mask);
23
24OutlineValue value = new OutlineValue();
25value.setDescription("Value description");
26value.setValueId(1);
27value.setValue("123456");
28value.setType(OutlineValueType.Number);
29
30code1.getValues().add(value);
31
32project.getOutlineCodes().add(code1);
33
34OutlineCodeDefinition code2 = new OutlineCodeDefinition();
35code2.setAlias("New rsc outline code2");
36code2.setFieldId(String.valueOf((int) ExtendedAttributeResource.OutlineCode2));
37code2.setFieldName("Outline Code2");
38
39OutlineMask mask2 = new OutlineMask();
40mask2.setSeparator("/");
41mask2.setLevel(1);
42mask2.setType(MaskType.Numbers);
43
44code2.getMasks().add(mask2);
45
46OutlineValue value2 = new OutlineValue();
47value2.setDescription("Value2 description");
48value2.setValueId(2);
49value2.setValue("987654");
50value2.setType(OutlineValueType.Number);
51
52project.save(dataDir + "Project.Mpp", SaveFileFormat.MPP);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.