Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The NetSuite Pro

The NetSuite Pro Logo The NetSuite Pro Logo

The NetSuite Pro Navigation

  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us
Home/ Real-World NetSuite Examples/Auto-Close Completed Projects & Tasks

Auto-Close Completed Projects & Tasks

💼 Business Problem

As projects mature, completed project tasks often remain open, and projects themselves stay active even after all tasks are finished. This causes:

  • Inaccurate project dashboards and resource reports
  • Overstated “active project” counts
  • Time or expenses accidentally booked to closed work

Managing projects in NetSuite can get messy when tasks and jobs remain open long after completion. This SuiteScript 2.1 example shows how to automatically close completed projects and tasks, helping your PMO maintain clean dashboards, improve reporting accuracy, and prevent accidental time entry on finished work. It’s one of the simplest yet most impactful NetSuite automations you can deploy for project management efficiency.

Goal:
Automatically identify and close:

  • Tasks with status “Completed” but not marked “Closed”
  • Projects where all tasks are closed and 100% complete

🧠 Approach

We’ll use a Scheduled Script (or Map/Reduce for large accounts) that:

  1. Searches for Project Tasks with Status = Completed and not Closed → sets Status = Closed.
  2. For each Project, checks if all tasks are closed; if yes → sets Project Status = Closed.
  3. Runs nightly (or weekly).
  4. Optionally emails a summary to the PMO team.

This approach ensures your Project module remains clean without manual maintenance.


🔧 Saved Search Setup

1️⃣ Project Task Search — “Completed Not Closed”

Type: Project Task
Criteria:

  • Status = Completed
  • % Complete = 100
  • Is Closed = F
    Results: Internal ID, Project, Status, % Complete

ID Example: customsearch_tasks_completed_notclosed

2️⃣ Project Search (optional)

If you’d like to close the Project automatically, the script can find all related tasks using the Project internal ID.


🧩 SuiteScript 2.1 — Scheduled Script

/**
 * @NApiVersion 2.1
 * @NScriptType ScheduledScript
 * Title: SCH | Auto-Close Completed Projects & Tasks
 * Author: The NetSuite Pro
 */
define(['N/search','N/record','N/log','N/runtime','N/email'], (search, record, log, runtime, email) => {

  const TASK_SEARCH_ID = 'customsearch_tasks_completed_notclosed';

  function execute() {
    try {
      const closedTasks = autoCloseTasks();
      const closedProjects = autoCloseProjects(closedTasks);

      // Optional summary email
      const summary = `
        <h3>Auto-Close Summary</h3>
        <p>Closed Tasks: ${closedTasks.length}</p>
        <p>Closed Projects: ${closedProjects.length}</p>
      `;
      email.send({
        author: runtime.getCurrentUser().id,
        recipients: 'pmo@yourcompany.com',
        subject: 'NetSuite Project Auto-Close Summary',
        body: summary
      });

    } catch (e) {
      log.error('Execution Error', e);
    }
  }

  function autoCloseTasks() {
    const ids = [];
    const s = search.load({ id: TASK_SEARCH_ID });
    s.run().each(r => {
      const id = r.getValue('internalid');
      const proj = r.getValue('project');
      try {
        record.submitFields({
          type: 'projecttask',
          id,
          values: { status: 'CLOSED' },
          options: { enableSourcing: false, ignoreMandatoryFields: true }
        });
        ids.push({ taskId: id, projectId: proj });
      } catch (e) {
        log.error(`Failed closing task ${id}`, e);
      }
      return true;
    });
    return ids;
  }

  function autoCloseProjects(closedTasks) {
    const closedProjects = [];
    const uniqueProjects = [...new Set(closedTasks.map(t => t.projectId).filter(Boolean))];

    uniqueProjects.forEach(projId => {
      try {
        if (allTasksClosed(projId)) {
          record.submitFields({
            type: 'job', // project record type
            id: projId,
            values: { entitystatus: 'CLOSED' }, // or your internal ID for “Closed”
            options: { enableSourcing: false, ignoreMandatoryFields: true }
          });
          closedProjects.push(projId);
        }
      } catch (e) {
        log.error(`Failed closing project ${projId}`, e);
      }
    });

    return closedProjects;
  }

  function allTasksClosed(projectId) {
    const taskSearch = search.create({
      type: 'projecttask',
      filters: [['project','anyof',projectId],'AND',['status','noneof',['CLOSED']]],
      columns: ['internalid']
    });
    const result = taskSearch.runPaged({ pageSize: 1 }).count;
    return result === 0;
  }

  return { execute };
});

✅ Testing Checklist

  1. Create a few Project Tasks with status = Completed (not closed).
  2. Create a Project with all tasks at 100% complete.
  3. Run the Scheduled Script manually → tasks and projects should now show as Closed.
  4. Check the summary email to confirm counts.
  5. Verify that users can no longer log time or expenses to closed tasks.

🧩 Optional Enhancements

EnhancementDescription
Email per projectNotify Project Manager when their project is closed.
Auto-Archive FilesMove completed project files to an archive folder.
Add SuiteAnalytics reportTrack how many projects auto-closed monthly.
Include % complete logicOnly close projects with 100% progress.
Auto-flag stale tasksAdd logic to close tasks older than X days in “Completed” status.

📌 Summary

GoalResult
Automatically close completed tasks & projects✅ Clean dashboards
Prevent time/expense on finished work✅ Improved accuracy
Reduce manual PMO cleanup✅ Fully automated nightly run
Share
  • Facebook

Sidebar

Ask A Question

Stats

  • Questions 6
  • Answers 6
  • Best Answers 0
  • Users 3
  • Popular
  • Answers
  • Rocky

    Issue in running a client script in NetSuite SuiteScript 2.0 ...

    • 1 Answer
  • admin

    How can I send an email with an attachment in ...

    • 1 Answer
  • admin

    How do I avoid SSS_USAGE_LIMIT_EXCEEDED in a Map/Reduce script?

    • 1 Answer
  • admin
    admin added an answer The issue is usually caused by following Wrong script file… September 14, 2025 at 10:33 pm
  • admin
    admin added an answer Steps to send an Invoice PDF by email: define(['N/email', 'N/render',… August 28, 2025 at 3:05 am
  • admin
    admin added an answer This error means your script hit NetSuite’s governance usage limit… August 28, 2025 at 3:02 am

Top Members

Rocky

Rocky

  • 1 Question
  • 22 Points
Begginer
Sophie1022

Sophie1022

  • 0 Questions
  • 20 Points
Begginer
admin

admin

  • 5 Questions
  • 2 Points

Trending Tags

clientscript netsuite scripting suitescript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Menu

  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us

Quick Links

  • NetSuite Scripting
  • NetSuite Customization
  • NetSuite Advanced PDF Template
  • NetSuite Integration
  • NetSuite Reporting & Analytics

Subscribe for NetSuite Insights....

© 2025 The NetSuite Pro. All Rights Reserved