none
CSOM - get resource login name RRS feed

  • Question

  • can someone provide an example of how to get resource login name by using SCOM? 

    here is what i have so far and the error i am getting.

     

    projContext = new ProjectContext(pwaPath);

                CustomFieldCollection customFields = projContext.CustomFields;
                EnterpriseResourceCollection resources = projContext.EnterpriseResources;


                projContext.Load(projContext.EnterpriseResources);
                projContext.ExecuteQuery();


                projContext.Load(projContext.CustomFields);
                projContext.ExecuteQuery();

                   

     foreach (EnterpriseResource rs in projContext.EnterpriseResources)
                {
                    foreach (DataRow row in OracleTable.Rows)
                    {
                        if (rs.User.LoginName == row["user_nm"].ToString())      //BREAKING HERE
                        { 

                            if (rs.ResourceType.ToString() == "Work")
                            {
                               }

                          }

                    }

      


    tatiana

    Tuesday, December 15, 2015 7:26 PM

Answers

  • rs.User needs to be loaded before you can use it. By loading EnterpriseResources the way you did, the associated User objects for each of the resources didn't get loaded.

    Instead of using this:

    projContext.Load(projContext.EnterpriseResources);

    Use this:

                projContext.Load(projContext.EnterpriseResources, items=>items.IncludeWithDefaultProperties(item=>item.User));


    Friday, December 18, 2015 3:43 PM