Read EPT Id and EPT Project plan template Id for a given EPT name using CSOM for Project server or Project Online

Hello Readers !

Thanks for reading this post. Here, I’m gonna show you a way to read the EPT Id and EPT associated project plan template id for a given EPT name using CSOM.

Scenario 1: Reading EPT Id : In real time, when we create a new project Programmatically with CSOM using a template, we need to provide the “Template Id” for the new project object. The below code will return the EPT id for the given EPT name.


private Guid GetEptId(string eptName)
        {
            Guid eptUid = Guid.Empty;
            try
            {               
                var eptList = context.LoadQuery(context.EnterpriseProjectTypes
                        .Where(ept => ept.Name == eptName));
                context.ExecuteQuery();
                eptUid = eptList.First().Id;// Returns the EPT ID
            }
            catch (Exception ex)
            {
                string msg = string.Format("GetEptUid: eptName = \"{0}\"\n\n{1}",
                    eptName, ex.GetBaseException().ToString());
                Response.Write(msg);
                // throw new ArgumentException(msg);
            }
            return eptUid;
        }

Scenario 2: Read EPT Project Plan template ID: Say for example you are developing a solution to merge multiple
templates, in that case, the project will be created with the first template with the EPT Id, but to merge the
second template we need to read the schedule data to merge. Here, we need to know the schedule template project id of the
given EPT. The below code will give you the associated schedule template id for the given EPT. Once we have the
schedule template project Id, we can send a request to the server to load the corresponding project id data.


 private Guid GetEptScheduleTemplateId(string eptName)
        {
            Guid eptScheduleId = Guid.Empty;
            try
            {
                var eptList = context.LoadQuery(context.EnterpriseProjectTypes
                        .Where(ept => ept.Name == eptName));
                context.ExecuteQuery();
                eptScheduleId = eptList.First().ProjectPlanTemplateId;
            }
            catch (Exception ex)
            {
                string msg = string.Format("GetEptScheduleTemplateUid: eptName = \"{0}\"\n\n{1}",
                    eptName, ex.GetBaseException().ToString());
                Response.Write(msg);
                // throw new ArgumentException(msg);
            }
            return eptScheduleId;
        }

Ofcourse, both the codes are same but the only difference is at this line

1. eptUid = eptList.First().Id;// Returns the EPT ID
2. eptScheduleId = eptList.First().ProjectPlanTemplateId; //Returns the EPT Project plan Template ID

That’s it. Thanks.