Forum Discussion

Joseph_An's avatar
Joseph_An
Creator II
8 years ago

How set Role and Name with default when Project is created?

Hi expert, When new "Project" is created by saving, I need to set Role and Name in Team tab of new project as default. For example, when a user create new project, using C#method I'd like to add as below: Role                           Name Project Executive            Susan Senior Supplier               James Senior User                      Philip Would you please help how to do this requirement?   Thank you so much.    

4 Replies

  • 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.
    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
  • Hi Christopher, Thank you so ~~~~~ much for your reply. Have a good day.
  • Hi Christopher, Can I ask you one more thing? When I created new project with the code below, I could see "Project Executive" and so on are added automatically. However, I found that "sort order" doesn't work. Would you please check whether I did something wrong in the codes below? Thank you so much. Item item_proj_exec = this.createRelationship("Project Team", "add"); item_proj_exec.setProperty("role", "Project Executive"); item_proj_exec.setProperty("sort_order", "10"); Item item_proj_exec_result = item_proj_exec.apply(); Item item_seni_supplier = this.createRelationship("Project Team", "add"); item_seni_supplier.setProperty("role", "Senior Supplier"); item_seni_supplier.setProperty("sort_order", "20"); Item item_seni_supplier_result = item_seni_supplier.apply(); Item item_seni_user = this.createRelationship("Project Team", "add"); item_seni_user.setProperty("role", "Senior User"); item_seni_user.setProperty("sort_order", "30"); Item item_seni_user_result = item_seni_user.apply();  
  • Hello, It doesn't look like there's an issue with the code provided. Could you run a search with the AML below to check the value of the sort_order in the database?
    <AML>
    <Item type="Project Team" action="get">
    <source_id>YOUR_PROJECT_ID</source_id>
    </Item>
    </AML>
    Chris
    Christopher Gillis Aras Labs Software Engineer