Forum Discussion
christopher_gillis
8 years agoCommunity Manager
Hi Joseph,
You can accomplish this by using an onBeforeAdd Server Event on the Project ItemType to add these relationships using code similar to the sample below.
Christopher Gillis Aras Labs Software Engineer
Innovator inn = this.getInnovator();
// Add a default project team whenever a Project is created
Item projectTeam = this.getRelationships("Project Team");
// Allow the default to be overridden if the user defines another team
if (projectTeam.getItemCount() >= 1)
{
return this;
}
// Add Susan
Item susan = this.createRelationship("Project Team", "add");
susan.setProperty("related_id", "8ADEF377932547CB8684EF598BADC491");
susan.setProperty("role", "Project Executive");
// Add James
Item james = this.createRelationship("Project Team", "add");
james.setProperty("related_id", "AECB07A16E0B4D12AF4CD098C783E073");
james.setProperty("role", "Senior Supplier");
// Add Phillip
Item phillip = this.createRelationship("Project Team", "add");
phillip.setProperty("related_id", "561695BD17B64105AD259D37765BD769");
phillip.setProperty("role", "Senior User");
return this;
I've hard-coded in the IDs of the Identities I want to add in the above example, but you could also perform a lookup based on the names of your users. Additionally, I've written this method in such a way that this team will only be added as a default if no other team members are defined before the Project is saved. You can remove the if statement at the beginning of this sample if you wish for these team members to always be added.
Chris
Christopher Gillis Aras Labs Software Engineer