Create Project Programmatically using JavaScript Object Model(JSOM)

Create Project Programmatically using JavaScript Object Model(JSOM)

In this post, I will describe you to Create Project Programmatically using JavaScript Object Model(JSOM).A project can be created manually, Bu the requirement is to create the project in bulk then we need to create project programmatically.A project can we created using CSOM and PSI also.

Create Project in Project Online using CSOM.

Create Project using PSI Programmatically Project Server 2013.

<script src="../_layouts/15/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../_layouts/15/sp.runtime.js"></script>    
    <script type="text/javascript" src="../_layouts/15/sp.js"></script>
    <script type="text/javascript" src="../_layouts/15/ps.js"></script>



<script>

    var projectOBJ;
    $(document).ready(function () {

        SP.SOD.executeOrDelayUntilScriptLoaded(CreateProjectOnPWA, "PS.js");
    });
       
    function CreateProjectOnPWA() {

           
            var projectContext = PS.ProjectContext.get_current();

           
            var ProjectcreationInformation = new PS.ProjectCreationInformation();
            ProjectcreationInformation.set_name("Demo Project JSOM 1");

          
            ProjectcreationInformation.set_description("Created through the JSOM.");
            ProjectcreationInformation.set_start("2013-10-01 09:00:00.000");

          
            projectOBJ = projectContext.get_projects();

           
            projectOBJ.add(ProjectcreationInformation);

           
            ProjectcreationInformation.set_name("Demo Project JSOM 2");
            projectOBJ.add(ProjectcreationInformation);

           
            var Jobupdate = projectOBJ.update();
            projectContext.waitForQueueAsync(Jobupdate, 20, GetProjectInfo);
        }
    function GetProjectInfo(response) {
            var projectContext = projectOBJ.get_context();
            projectContext.load(projectOBJ, 'Include(Name, Description, StartDate, Id)');
            projectContext.executeQueryAsync(IterateThroughProjects, QueryFailed);
        }       
        function IterateThroughProjects(response) {           
            var enumerator = projectOBJ.getEnumerator();
            while (enumerator.moveNext()) {
                var project = enumerator.get_current();              
                
                alert(project.get_name());
                alert(project.get_description());
                alert(project.get_startDate());
                alert( project.get_id());
            }          
           
        }
        function QueryFailed(sender, args) {
           alert('Request failed: ' + args.get_message());
        }
    
</script>

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!