none
Using JavaScript to add existing sharepoint site to PWA projects list RRS feed

  • Question

  • I have created Sharepoint site using project site template and have to add this site to projects list on PWA.

    I used PS.ProjectCreationInformation but not sure how to configure it for to add existing sharepoint site as a project.

    I set values for name and startDate but the question is how to set value for taskList.

    I tried to use list guid (set_taskList([GUID])) but project was not added to PWA.

    I have also tried to set taskList property directly to list object, retrieved from my sharepoint site:

    var ctx = new SP.ClientContext(mysiteurl);
    var web = ctx.get_web();
    var lists = web.get_lists();
    var list = lists.getByTitle('MyTaskListName');
    ctx.load(lists);
    ctx.load(list);
    ctx.executeQueryAsync( function (){
    
    //set task list
    projectCreationInformation.set_taskList(list);
    
    projects.add(projectCreationInformation);
    var updateJob = projects.update();
    projectCtx.waitForQueueAsync(updateJob, 10, function(){})
    
    //after this request I got error message: "TypeError: o is undefined"
    
    });

    I supposed that projectCreationInformation.set_taskList method shoud work like the same method SP.Workflow.WorkflowAssociationCreationInformation.set_taskList(value) but I haven't find any info how to use it correctly.

    Is there any other ways to add existing sharepoint site to PWA project list?

    Friday, April 19, 2013 8:18 AM

Answers

  • U have two different context. U must use one of context like as:

    var ctx= new PS.ProjectContext(mysiteurl);
    
    var lists= ctx.get_web().get_lists();
    
    var list = lists.getByTitle('MyTaskListName');
    
    ctx.load(lists);
    
    ctx.load(list);
    
    ctx.executeQueryAsync(function(){
       var projects=ctx.get_projects();
       var pi = new PS.ProjectCreationInformation();
       pi.set_name('My Project Name');
       pi.set_start('2013-10-10');
       pi.set_taskList(list);
       projects.add(pi);
       var job=projects.update();
       ctx.waitForQueueAsync(job,10,function(){});
    });
    Use one context for query list and add project.
    Friday, April 19, 2013 12:49 PM