Requested item not getting closed even after all sc tasks are closed

BijoyDeb
Tera Contributor

Hi all,

 

I am facing a strange issue in catalog management.

Sometimes, RITM's state is not getting changed to closed complete even if all catalog tasks under it are closed.

Usually, its working fine, but some RITMs are not getting closed and I am not sure what might be the reason behind this.

 

Also, its not for specific item, its happening for any random item.

 

Has anyone faced such issue before?

 

Please let me know what should I check for this.

 

Thanks!

3 ACCEPTED SOLUTIONS

@BijoyDeb 

yes from workflow it's also possible.

Instead of updating multiple workflows you can have after update BR on sc_task to close RITM once all sc tasks are closed

something like this

you can use after update BR on sc_task

Condition: State [IS ONE OF] Closed Complete/Closed Incomplete

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord('sc_task');
	gr.addQuery('request_item', current.request_item); 
	gr.addQuery('active', true);
	gr.query();
	if(!gr.next()){
		var ritm = current.request_item.getRefRecord(); 
		ritm.state = 3;
		ritm.update();
	}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

yes, if you want it for all catalog items then go ahead with business rule on sc_task table.

Try this:

Table : sc_task

After Update  BR with condition as State CHANGES TO  Closed

 

var gr = new GlideRecord('sc_task');
	gr.addQuery('request_item', current.request_item); 
	gr.addQuery('active', true);
	gr.query();
	if(!gr.next())
      {
		var ritm = new GlideRecord('sc_req_item');
                ritm.get(current.request_item);
		ritm.state = 3;
		ritm.update();
	}

 

 

But this approach conflicts with flows and probably causes issues.

 

Regards,

Sumanth

 

View solution in original post

Be careful using the BR approach. If you have a workflow that does one task then another, the BR could close the RITM before the second task is created, thereby killing the workflow. If you can narrow down the specific RITMs where this is happening, you may want to use a very specific condition if you decide to go this route.

View solution in original post

21 REPLIES 21

Hi Jennifer,

I have a flow that has one task created on a Catalog Request.  When requested it looks like this:

Request>1 Requested item>1 Catalog Task.

When the catalog task is closed (Completed, Incomplete or Skipped), I want the RITM to have the same state - Closed (Completed, Incomplete or Skipped) AND the Request to have the same state.

Is that something I can do in the flow, or do I need a BR to close the RITM and the Request?

What would that look like in a flow (if that's possible)?

 

Also, we're new to SN and we're implementing it in May.  I would think that the "philosophy" of request management would be: 

1) If all tasks are closed, close the RITM

2) if all RITMS are closed, close the Request

 

Is that not so?

 

Thank you so much for taking the time to answer questions for the community.

 

Yes, you can do both of them in the Flow, but I think there's an OOTB BR that closes a Request when all its RITMs close, so you wouldn't need to do that. This is an example of a bare-bones Flow for a RITM: 

JenniferRah_0-1741953471669.png

 

The last action sets the State of the RITM. Since that's a close state, a BR runs to make it inactive, so there's no need to set the active flag.

 

JenniferRah_1-1741953541465.png

 

Jennifer,

Thank you for the prompt response.  I've got this to work.

 

I just have one question:

How do i get the RITM and Request to have the same state at the task?

For example, if the task is "Closed Skipped" (indicating the work was not needed) I want the RITM to show "Closed Skipped". 

A part of my says "who cares" but I think we'd want the Request and the RITM to indicate if the work was completed.  If I run a report on Requests, I'd want it to show how may were not completed, vs completed.  Maybe I'm overthinking. I just want to be precise in what we're  showing.

Thank you again.

 

Technically speaking, Closed Skipped isn't a valid state for RITMs. I understand what you mean, though. You can do an "If" statement after the task runs. If the final state of the Task is Closed Complete, make the state of the RITM Closed Complete. If the final state of the Task is anything else, set the state of the RITM to "Closed Incomplete" or something like that. 

 

Of course, you can always add custom states to your RITM and Request to make them match the ones in the Catalog Task, but that can cause issues with other things, so it's best to keep things OOTB when you can.

Thank you so much Jennifer.

I appreciate your wisdom.

Have a great weekend.