Delete Project Programmatically using JavaScript Object Model(JSOM)

Delete Project Programmatically using JavaScript Object Model(JSOM)

In this article, I will describe to Delete Project Programmatically using JavaScript Object Model(JSOM).In Project server a project can we deleted manually.But when we need to delete projects in bulk then we need to write some code.A Project can we deleted using CSOM and PSI also.

Delete Project Programmatically Project Online using CSOM

<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 projectContext;
    var projectOBJ;

    $(document).ready(function () {

        SP.SOD.executeOrDelayUntilScriptLoaded(GetProjectInfo, "PS.js");
    });
   
    function GetProjectInfo() {
        projectContext = PS.ProjectContext.get_current();
        projectOBJ = projectContext.get_projects();
        projectContext.load(projectOBJ, 'Include(Name, Description, StartDate, Id)');
        projectContext.executeQueryAsync(IterateThroughProjects, QueryFailed);
    }   
    function IterateThroughProjects(response) {       
        var Projectenumerator = projectOBJ.getEnumerator();
        while (Projectenumerator.moveNext()) {
            var project = Projectenumerator.get_current();
            
            if (project.get_name() == "Test Project 1") {
                DeleteProject(project.get_id());
            }
           
        }       
    }   
    function DeleteProject(GUID) {

        var project = projectOBJ.getById(GUID);
        projectOBJ.remove(project);
        var Jobremove = projectOBJ.update();
        projectContext.waitForQueueAsync(Jobremove, 10, QueueJobSent);
    }

   
    function QueueJobSent(response) {
        alert( 'JobState = ' + response + '. Job in Quee');
    }
    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 !!