Search code examples
c#csomproject-online

Fetching ProjectSiteUrl from Project Online not working


I have written the following code to get ProjectSiteUrl property from a project Published in Project Online

using (ProjectContext projContext = new ProjectContext(pwaUrl))
{
    using (SecureString securePassword = new SecureString())
    {
        Helper.GetSecurePassword(projContext, securePassword, emailID, password);

        for (int i = 0; i < listGuid.Count; i++)
        {
            #region Load Project
            string spoGuid = listGuid[i].ProjectGuid;

            if (!string.IsNullOrEmpty(spoGuid))
            {


                Guid id = Guid.Parse(spoGuid);

                var projBlk = projContext.LoadQuery(
                        projContext.Projects
                        .Where(p =>
                            p.Id == id
                        )
                        .Include(p => p.Id,
                        p => p.Tasks,
                        p => p.TaskLinks,
                        p => p.ScheduledFromStart,
                        p => p.ProjectSiteUrl,
                            p => p.Name,
                            p => p.IncludeCustomFields,
                            p => p.IncludeCustomFields.CustomFields,
                            P => P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(
                                lu => lu.LookupTable,
                                lu => lu.LookupEntries,
                                lu => lu.LookupEntries.IncludeWithDefaultProperties(
                                    entry => entry.FullValue,
                                    entry => entry.InternalName)
                            )
                        )
                    );

                projContext.ExecuteQuery();

                poFieldValues.Add(LoadProjectsinPO(projBlk, projContext));

            }
            #endregion
            //if (i > 5)
            //{
            //    break;
            //}
            if (i % 5 == 0)
            {
                Thread.Sleep(sleepDelay);
            }
        }
    }
}

On trying to access the ProjectSiteUrl property I'm getting null. I used to get the correct ProjectSiteUrl but for last few weeks i'm getting null. There were no changes to the code.

Did something change in the way we access this property in Project Online?


Solution

  • I had modified the order of loading properties in Load Query and ProjectSiteUrl is loading fine now. Don't know why it is working though. Would be grateful if someone explains this.

     var projBlk = projContext.LoadQuery(
                            projContext.Projects
                            .Where(p =>
                                p.Id == id
                            )
                            .Include(p => p.Id,
                            p => p.ProjectSiteUrl, // Moved ProjectSiteUrl as second loading parameter.
                            p => p.Tasks,
                            p => p.TaskLinks,
                            p => p.ScheduledFromStart,
    
                                p => p.Name,
                                p => p.IncludeCustomFields,
                                p => p.IncludeCustomFields.CustomFields,
                                P => P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(
                                    lu => lu.LookupTable,
                                    lu => lu.LookupEntries,
                                    lu => lu.LookupEntries.IncludeWithDefaultProperties(
                                        entry => entry.FullValue,
                                        entry => entry.InternalName)
                                )
                            )
                        );