WBS Associated with a Task

WBS codes, work breakdown structure codes, lets you assign outline numbers to tasks according to the needs of your business. It’s a method for applying a customized outline scheme to a project. Aspose.Tasks for Java supports this feature.

Working with Work Breakdown Structure

The WBS and WBSLevel properties exposed by the Tsk class is used to read and write a tasks work breakdown structure:

Microsoft Project View of WBS

To view WBS information in Microsoft Project:

  1. On the Task Entry Form, select the Insert menu and then Column.
  2. Add the WBS column.

Work breakdown structure in Microsoft Project

WBS associated with tasks

Getting WBS in Aspose.Tasks

The following examples show how to get a task’s WBS value using Aspose.Tasks.

 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(WbsAssociatedWithTask.class);
 4
 5Project project = new Project(dataDir + "input.mpp");
 6
 7// Create a ChildTasksCollector instance
 8ChildTasksCollector collector = new ChildTasksCollector();
 9
10// Collect all the tasks from RootTask using TaskUtils
11TaskUtils.apply(project.getRootTask(), collector, 0);
12
13// Parse through all the collected tasks
14for (Task tsk : collector.getTasks()) {
15    System.out.println(tsk.get(Tsk.WBS));
16    System.out.println(tsk.get(Tsk.WBS_LEVEL));
17    // set custom WBS
18    tsk.set(Tsk.WBS, "custom wbs");
19}

Renumber WBS Codes

Aspose.Tasks for Java API can renumber WBS codes similar to MSP’s “Renumber” function.

 1String dataDir = Utils.getDataDir(WbsAssociatedWithTask.class);
 2        
 3Project project = new Project(dataDir + "RenumberExample.mpp");
 4
 5List<Task> tasks = (List<Task>) project.getRootTask().selectAllChildTasks();
 6
 7System.out.println("WBS codes before: ");
 8
 9// output: ""; "1"; "2"; "4"
10for (Task task: tasks)
11{
12    System.out.println("\"" + task.get(Tsk.WBS) + "\"" + "; ");
13}
14
15// project.RenumberWBSCode(); // this overload could have used too
16List<Integer> listIds = new ArrayList<>();
17listIds.add(1);
18listIds.add(2);
19listIds.add(3);
20project.renumberWBSCode(listIds);
21
22System.out.println("\nWBS codes after: ");
23
24// output: ""; "1"; "2"; "3"
25for (Task task: tasks)
26{
27    System.out.println("\"" + task.get(Tsk.WBS) + "\"" + "; ");
28}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.