Where to find closeRelatedTasks(current);

Aman Gurram
Giga Expert

Hello All,

I am trying to find the body of the function closeRelatedTasks(current); in the below business rule

Name: SNC - ITIL - Resolve Related Incidents         (Global)

Script:

if (current.problem_state.changesTo(4))

{

      resolveRelatedIncidents(current);

    closeRelatedTasks(current);

}

//

// Resolve any incidents that are related to the current problem

//

function resolveRelatedIncidents(me)

{

      var incident = new GlideRecord("incident");

      incident.addQuery("problem_id", "=", me.sys_id);

      incident.query();

      while (incident.next()) {

      if ( incident.active == true )

    {

                  ............................................

                  ...........................................

                  ............................

                  incident.state.setValue(6);

                  incident.comments = msg;

                  incident.update();

    }

  }

}

The business rule gets executed without any errors when a new problem is inserted or updated in the Problems table. When the function is not defined in the first place, I am wondering from where is the function closeRelatedTasks(current); is getting executed when its not defined in the first place. Any help is greatly appreciated.

5 REPLIES 5

_ukasz Rybicki
Giga Guru

Problem Name: Locating the closeRelatedTasks(current) Function in ServiceNow 🧩


General Solution Proposal:

The closeRelatedTasks(current) function is defined within the global business rule named "SNC - ITIL - Close Related", which is set on the Global table. This setup allows the function to be accessible across multiple tables and scripts within the ServiceNow instance.


Detailed Step-by-Step Solution:

  1. Navigate to Business Rules:

    • Go to System Definition > Business Rules in the Application Navigator.

  2. Search for the Global Business Rule:

    • In the list view, set the filter to:

      • Table: Global

      • Name: SNC - ITIL - Close Related

    • This will help you locate the specific business rule where the function is defined.

  3. Access the Script:

    • Open the "SNC - ITIL - Close Related" business rule.

    • Scroll down to the Script section to view the function definition.

  4. Review the Function:

    • The closeRelatedTasks(current) function is defined here and is used to close related tasks when a parent task is closed.

    • The function typically includes logic to:

      • Query for child tasks related to the current record.

      • Update the state of these child tasks to closed.

      • Add appropriate comments or notes.

  5. Usage in Other Business Rules:

    • This function is often called in other business rules, such as:

      • "SNC - ITIL - Resolve Related Incidents" on the Problem table.

      • "SNC - ITIL - Close Related" on the Incident table.

    • These business rules utilize the function to ensure related tasks or incidents are appropriately closed when the parent record is closed.


Example Solution:

When a Problem record is moved to the "Resolved" state, the business rule "SNC - ITIL - Resolve Related Incidents" triggers and calls the closeRelatedTasks(current) function. This function then closes all related Incident records associated with the Problem.


Testing the Solution:

  1. Create a Problem Record:

    • Navigate to the Problem table and create a new record.

  2. Associate Incidents:

    • Link one or more Incident records to the Problem record.

  3. Resolve the Problem:

    • Change the state of the Problem record to "Resolved."

  4. Verify Related Incidents:

    • Check the associated Incident records to confirm they have been moved to the "Resolved" or "Closed" state, depending on your instance's configuration.


Sources:

  1. ServiceNow Community - Where to find closeRelatedTasks(current);

    • Link

    • Discussion on locating the definition of the closeRelatedTasks(current) function within the global business rule.

  2. ServiceNow Community - SNC - ITIL - Close Related for Incidents

    • Link

    • Insights into how the closeRelatedTasks(current) function is utilized within the Incident management process.

  3. ServiceNow Community - Related incidents still not closing after activating "SNC - ITIL - Close Related"

    • Link

    • Troubleshooting steps for scenarios where related incidents are not closing as expected.


If you need assistance modifying the function to exclude specific task types or to customize its behavior further, feel free to ask! 😊