Use ProjectService when working with project records.
Whenever a Service operation requires ProjectService, set up ProjectService using the following code:
ProjectService projectService = platform.getProjectService(); |
The following samples update a project record by adding an embedded project to the project. As shown in these samples, you can use Project methods to add the embedded project.
EmbeddedEntity embeddedProject = project.addEmbeddedEntity("unique code"); //or EmbeddedEntity embeddedProject = project.addEmbeddedEntityWithName("unique code", "name"); //or EmbeddedEntity embeddedProject = project.addEmbeddedEntityWithNumberString("unique code", "id number as a string"); //or EmbeddedEntity embeddedProject = project.addEmbeddedEntity("unique code", "name", "id number as a string"); |
The following sample changes the phase of a project and updates the record. While making these changes, you can use API interface methods to update objects in the project record, such as the project name.
project.setContact(contact); project.setMainAssignee(assignee); projectService.changePhaseWithUpdate(project, "phase code of the phase to change to"); |
The following sample returns the child projects of a parent project.
List<Project> childProjects = projectService.getChildProjects(project, "unique code of the child Custom Object Definition"); |
The following samples return an existing project. The second sample includes a ProjectService.search() method. This search() method is different from the ResourceService.search() methods because the ProjectService.search() method includes the unique code of an existing project as a parameter.
//Reading a project //The id initialized here is the id of an existing project Long id = 1234567890L; Project project = projectService.read(id);
//Searching for a project List<Project> search("unique code", "search view key"); |
The following sample deletes and existing project.
//The id initialized here is the id of an existing project Long id = 1234567890L; projectService.delete(id); |