简体   繁体   中英

CSOMUnknownUser error on working with draft project in Project Server 2013 CSOM

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()

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));
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

Please add user credential in projectcontext as below:

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

context.Credentials = cred;

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();

You must use the elevated permission for checkout the draft project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM