<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question need to close RITM after all sc_tasks are completed in CSM forum</title>
    <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542516#M32771</link>
    <description>&lt;P&gt;For one RITM, we built two sc_tasks. When I try to close one sc_task, RITM closes but another sc_task remains open. Can somebody assist me in closing all sc_tasks before RITM closes?&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2023 05:48:00 GMT</pubDate>
    <dc:creator>Vani14</dc:creator>
    <dc:date>2023-04-24T05:48:00Z</dc:date>
    <item>
      <title>need to close RITM after all sc_tasks are completed</title>
      <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542516#M32771</link>
      <description>&lt;P&gt;For one RITM, we built two sc_tasks. When I try to close one sc_task, RITM closes but another sc_task remains open. Can somebody assist me in closing all sc_tasks before RITM closes?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 05:48:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542516#M32771</guid>
      <dc:creator>Vani14</dc:creator>
      <dc:date>2023-04-24T05:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: need to close RITM after all sc_tasks are completed</title>
      <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542525#M32772</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By creating a Business Rule on the sc_task table that triggers when a task is closed. In the Business Rule, you can check if all the related sc_tasks are closed, and if so, you can close the associated RITM.&lt;/P&gt;&lt;P&gt;Here is an example of a Business Rule script that you can use as a starting point:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// Get the current sc_task and its associated RITM
var currentTask = current;
var currentRITM = currentTask.request_item;

// Get all the sc_tasks associated with the RITM
var taskGr = new GlideRecord('sc_task');
taskGr.addQuery('request_item', currentRITM);
taskGr.query();

// Check if all the sc_tasks are closed
var allTasksClosed = true;
while (taskGr.next()) {
  if (taskGr.getValue('state') != '7') { // '7' is the state value for Closed
    allTasksClosed = false;
    break;
  }
}

// If all sc_tasks are closed, close the associated RITM
if (allTasksClosed) {
  currentRITM.setValue('state', 3); // '3' is the state value for Closed Complete
  currentRITM.update();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Rahul Kumar&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 05:57:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542525#M32772</guid>
      <dc:creator>Rahul Kumar17</dc:creator>
      <dc:date>2023-04-24T05:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: need to close RITM after all sc_tasks are completed</title>
      <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542537#M32773</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/242263"&gt;@Vani14&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can use after update BR on sc_task with proper conditions for State value&lt;/P&gt;
&lt;P&gt;Condition: State [IS ONE OF] Closed complete, Closed incomplete, Closed skipped&lt;/P&gt;
&lt;P&gt;Script:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	
	// check if there is no active task for this RITM
	
	var gr = new GlideRecord("sc_task");
	gr.addActiveQuery();
	gr.addQuery("request_item", current.request_item);
	gr.setLimit(1);
	gr.query();
	if (!gr.hasNext()) {
		var ritm = current.request_item.getRefRecord();
		ritm.state = 3;
		ritm.update();
	}

})(current, previous);&lt;/LI-CODE&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;P&gt;you can also use Flow designer with no script for this&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 06:04:50 GMT</pubDate>
      <guid>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542537#M32773</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-04-24T06:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: need to close RITM after all sc_tasks are completed</title>
      <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542648#M32777</link>
      <description>&lt;P&gt;we are using this script is it correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(function executeRule(current, previous /*null when async*/) {&lt;/P&gt;&lt;P&gt;var gr=new GlideRecord('sc_task');&lt;BR /&gt;gr.addQuery('request_item',current.request_item);&lt;BR /&gt;gr.addQuery('state', '!=',current.state);//checking if all tasks are closed&lt;BR /&gt;if(!gr.next())&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;var grr = new GlideRecord('sc_req_item');&lt;BR /&gt;grr.get(current.request_item);&lt;BR /&gt;&lt;BR /&gt;grr.state=current.state;&lt;/P&gt;&lt;P&gt;grr.update();&lt;BR /&gt;}&lt;BR /&gt;})(current, previous);&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 07:51:53 GMT</pubDate>
      <guid>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542648#M32777</guid>
      <dc:creator>Vani14</dc:creator>
      <dc:date>2023-04-24T07:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: need to close RITM after all sc_tasks are completed</title>
      <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542655#M32778</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/242263"&gt;@Vani14&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please use script I shared above.&lt;/P&gt;
&lt;P&gt;sharing again with some changes&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	
	// check if there is no active task for this RITM
	
	var gr = new GlideRecord("sc_task");
	gr.addActiveQuery();
	gr.addQuery("request_item", current.request_item);
	gr.setLimit(1);
	gr.query();
	if (!gr.hasNext()) {
		var ritm = current.request_item.getRefRecord();
		ritm.state = current.state;
		ritm.update();
	}

})(current, previous);&lt;/LI-CODE&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 07:54:31 GMT</pubDate>
      <guid>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542655#M32778</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-04-24T07:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: need to close RITM after all sc_tasks are completed</title>
      <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542670#M32780</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/265966"&gt;@Ankur Bawiskar&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;its not working when i close one task its automatically closing RITM, another task is in open state.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 08:05:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542670#M32780</guid>
      <dc:creator>Vani14</dc:creator>
      <dc:date>2023-04-24T08:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: need to close RITM after all sc_tasks are completed</title>
      <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542718#M32782</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/242263"&gt;@Vani14&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;share your BR configuration screenshot and latest script&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 08:49:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542718#M32782</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-04-24T08:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: need to close RITM after all sc_tasks are completed</title>
      <link>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542786#M32783</link>
      <description>&lt;P&gt;i did a mistake script is working thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 09:31:20 GMT</pubDate>
      <guid>https://www.servicenow.com/community/csm-forum/need-to-close-ritm-after-all-sc-tasks-are-completed/m-p/2542786#M32783</guid>
      <dc:creator>Vani14</dc:creator>
      <dc:date>2023-04-24T09:31:20Z</dc:date>
    </item>
  </channel>
</rss>

