Updating a project is similar to updating other record types, such as contacts. You need to use the ProjectRepository's updateProject method. In addition, from the type class, ProjectUpdate, use provided methods to identify the target record and update its property values. Before you can start, you need to know the target project record's unique key.
You can add one or more embedded object records either at the time you update or create a project record. The example below illustrates how to add an embedded object record (Damage) to an existing project record (Dispute).
Note: Adding an embedded object record to a project is analogous to adding an assignee or relation to a project.
protected ProjectRepository projectRepository;
ProjectUpdate project = updateProject();
projectRepository.updateProject(project);
private ProjectUpdate updateProject() throws Exception {
String date = String.valueOf(new Date().getTime());
//the EntityTypeUniqueKey is an object's 4-character unique code; look this value up either in the Designer area Object Definitions list or from the database
String Entity_Type_Unique_Key = "DISP";
ProjectUpdate project = new ProjectUpdate();
//the next line identifies which record to update by its unique key
project.setUniqueKey("DISP_2468");
project.setEntityTypeUniqueKey(Entity_Type_Unique_Key);
project.setName("Small Claims Forster vs. Gloucster");
project.setClosedOn(date);
project.setIdNumber("Dispute_1001");
//the next three lines add a category to the project
Category cat = new Category();
//the category must already be created in TeamConnect ; you need to get the unique key from the TeamConnect GUI or database
cat.setUniqueKey("DISP EXTE");
project.getCategories().add(cat);
project.getEmbeddedEntityCreates().add(getEmbeddedEntityCreates());
return project;
}
public EmbeddedEntityCreate getEmbeddedEntityCreates() {
Date date = new Date();
// List<EmbeddedEntityCreate> embeddedEntities = new List<EmbeddedEntityCreate>();
EmbeddedEntityCreate embeddedEntity = new EmbeddedEntityCreate();
embeddedEntity.setName("Damage_1002");
//the embedded object or project object definition must already exist in TeamConnect ; you need to get the embedded object's 4-character unique key (Unique Code) from the TeamConnect GUI or database
embeddedEntity.setEntityTypeUniqueKey("DAMA");
embeddedEntity.setContactUniqueKey("cont_1004");
embeddedEntity.setIdNumber("Damage_1002");
Category catEmbedded = new Category();
//the embedded object's category must already exist in TeamConnect; you need to get the corresponding category's unique key from the TeamConnect GUI or database
catEmbedded.setUniqueKey("DAMG");
embeddedEntity.getCategories().add(catEmbedded);
return embeddedEntity;
}