3
votes

I'm trying to work with Project Server 2013 CSOM and I can authenticate, read any information, create new project and so, but I have problem with draft projects, in any way when I want to execute query on draft project I receive error message CSOMUnknownUser and any thing. In my search's I didn't get special information about this error and
here is part of my codes:

context = GetContext(pwaInstanceUrl);

// Retrieve publish project named "New Project"
// if you know the Guid of project, you can just call context.Projects.GetByGuid()
csom.PublishedProject project = GetProjectByName(projectName, context);
if(project == null)
   {
      Console.WriteLine("Failed to retrieve expected data, make sure you set up server data right. Press any key to continue....");
                return;
   }

csom.DraftProject draft = project.CheckOut();

   // Retrieve project along with tasks & resources
context.Load(draft, p => p.StartDate,                                                         
                                    p => p.Description);                                                      
context.Load(draft.Tasks, dt => dt.Where(t => t.Name == taskName));                           
context.Load(draft.Assignments, da => da.Where(a => a.Task.Name == taskName &&                
                                                                    a.Resource.Name == localResourceName));   
context.Load(draft.ProjectResources, dp => dp.Where(r => r.Name == localResourceName));       
context.ExecuteQuery();

I receive error on last line context.ExecuteQuery()

3

3 Answers

1
votes

When executing these commands: context.Load(draft.Assignments, da => da.Where(a => a.Task.Name == taskName && a.Resource.Name == localResourceName));
context.Load(draft.ProjectResources, dp => dp.Where(r => r.Name == localResourceName));
try to remove the da=>da.Where(r => r.Name == localResourceName) bit and check if the Resource you are looking for really exists on the Project Server. Please let me know if it helped

1
votes

Please add user credential in projectcontext as below:

NetworkCredential cred = new NetworkCredential();
cred.Domain = "domain";
cred.UserName = "username";
cred.Password = "password";

context.Credentials = cred;
0
votes

I had the same problem. the problem was that the project which I was trying to edit, was checked out. I used this code to check it in , then I tried to do the rest of the job. here is the code to check it in first:

 DraftProject draft;
        draft = pubPro.Draft;
        JobState job1 = projectContext.WaitForQueue(draft.CheckIn(true), 20);

        draft = pubPro.CheckOut();
        projectContext.Load(draft);
        projectContext.ExecuteQuery();