Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
162 lines (116 sloc) 5.16 KB

Tasks

Task objects represent a user-created task on a file.

Get a Task's Information

Calling getInfo() on a task returns a snapshot of the task's info.

BoxTask task = new BoxTask(api, "id");
BoxTask.Info info = task.getInfo();

Get the Tasks on a File

You can get all of the tasks on a file by calling the getTasks() method.

BoxFile file = new BoxFile(api, "id");
List<BoxTask.Info> tasks = file.getTasks();

Add a Task to a File

A task can be added to a file with the addTask(String taskType, String message, Date dueDate) method.

BoxFile file = new BoxFile(api, "id");
Date dueAt = new Date();
file.addTask("review", "Please review this file.", dueAt);

Update a Task's Information

The message of a task can be changed with the updateInfo(BoxTask.Info fieldsToUpdate) method.

BoxTask task = new BoxTask(api, "id");
BoxTask.Info info = task.new Info();
info.setMessage("An edited message.");
task.updateInfo(info);

Delete a Task

A task can be deleted with the delete() method.

BoxTask task = new BoxTask(api, "id");
task.delete();

Get a Task's Assignments

Retreive a tasks assignments with the getAssignments() method.

BoxTask task = new BoxTask(api, "id");
task.getAssignments();

Get Information About a Task Assignment

To look up information about a task assignment by its ID, instantiate the BoxTaskAssignment object with the ID, and call getInfo() on the assignment. To retrieve only specific fields on the task assignment, call getInfo(String... fields) with the fields to retrieve.

String assignmentID = "4256974";
BoxTaskAssignment.Info assignmentInfo = new BoxTaskAssignment(api, assignmentID).getInfo();

Add a Task Assignment

An assignment can be added to a task with the addAssignment(BoxUser assignee) method.

BoxUser user = new BoxUser(api, "user-id")
BoxTask task = new BoxTask(api, "id");
task.addAssignment(user);

Delete a Task Assignment

An assignment can be deleted from a task with the delete() method on a BoxTaskAssignment instance.

BoxTaskAssignment taskAssignment = new BoxTaskAssignment(api, "id");
taskAssignment.delete();

Update a Task Assignment

A task assignment can be updated with the updateInfo(BoxTask.Info fieldsToUpdate) method.

String assignmentID = "12345";
BoxTaskAssignment taskAssignment = new BoxTaskAssignment(api, assignmentID);
BoxTaskAssignment.Info info = taskAssignment.getInfo();
info.addPendingChange("resolution_state", "approved");
taskAssignment.updateInfo(info);