none
CSOM 2013 set project owner RRS feed

  • Question

  • Hi.

    I'm writing a script to create projects in a Project Server 2013 Web App.

    But I didn't find how to set the owner of y projects. I would tlike to have a default user. Instead at the creation the owner is always my current account.

    My code :

    /// <summary>
    /// Create a project
    /// </summary>
    private PublishedProject CreateProject(ProjectsLoopEventArgs args)
    {
    	//	ProjectsLoopEventArgs contain data I need to create my project
    	PublishedProject project = null;
    
    	//  Define required informations
    	ProjectCreationInformation projInfo = new ProjectCreationInformation();
    	projInfo.Id = Guid.NewGuid();
    	projInfo.Name = args.Title;
    	projInfo.Description = args.Description;
    	projInfo.Start = args.ProjectStartDate.Date;
    	projInfo.EnterpriseProjectTypeId = this.ProjectType;
    
    	//  Create the project
    	project = this.Context.Projects.Add(projInfo);
    
    	return project;
    }
    
    /// <summary>
    /// Add a project to the project collection
    /// </summary>
    private void AddProject(ProjectsLoopEventArgs args)
    {
    	try
    	{
    		if (!ExistsProject(args))
    		{
    			//  create project
    			PublishedProject project = CreateProject(args);
    			//  update project owner
    			project.Owner = this.DefaultResource.User;  //doesnt work
    			//  update custom fields
    			UpdateProjectCustomFields(project, args);	//set my custom fields values, it works
    			//  add it to the project collection
    			QueueJob qJob = this.Context.Projects.Update();
    			JobState jobState = this.Context.WaitForQueue(qJob, this.Config.Timeout);
    			//  if job succeed
    			if (jobState == JobState.Success)
    			{
    				//  raise event
    				OnProjectAddedEvent(new ProjectAddedEventArgs(args));
    			}
    			else
    			{
    				//  raise event
    				OnQueueErrorEvent(new QueueErrorEventArgs(args, jobState, this.Config.Timeout));
    			}
    		}
    		else
    		{
    			//  raise event
    			OnProjectExistsEvent(new ProjectExistsEventArgs(args));
    		}
    	}
    	catch (Exception e)
    	{
    		OnScriptErrorEvent(new ScriptErrorEventArgs(args, e));
    	}
    }

    Have I miss something ?


    • Edited by Drakta Monday, June 2, 2014 2:33 PM
    Monday, June 2, 2014 2:30 PM

All replies