Create a NEW SCTASK after RITM ticket reopened

RC10
Tera Contributor

Hello Experts.

We developed one catalog item and once user submit the request, REQ ticket and RITM ticket will create initially.

And Once REQ ticket approved one more RITM will create and each RITM ticket have one unique SCTASK ticket.

When SCTASK ticket state changed to closed complete then RITM state will also change to Resolved and after 3 business days Job scheduler will change the RITM state from resolved to closed complete then REQ state also change to closed complete then RITM workflow will also end.

Note: Once both the RITM tickets state change to resolved then only REQ ticket state changing to resolved. [So far everything working fine and Existing business rule changing the REQ state to resolved after RITm tickets state are changed to resolved]

 

And now when any one RITM ticket reopened before the job scheduler close the RITM tickets, then we need to create one more SCTASK under reopened the RITM ticket and we need to change the REQ state as well from resolved to Work in progress.

Can anyone please advice the best approach to fulfill the requirement.

 

Many thanks for the support.

1 ACCEPTED SOLUTION

Hi @RC 

In that case you need to follow the steps below and then do it:

1) First create a hidden field on Requested Item Table say name it as "Check Reopen" and type of the field will be as "True/False" as shown below:

find_real_file.png

2) Now create a Before Update business Rule as per details shared below:

BR Details:

Table Name : Requested Item

When: Before Update

Condition: State Changes to Reopen and Check Reopen is False

Script:

This BR will set the value of the hidden field to True only once when any of the RITM is moved to Reopen. So using this you can identify for which RITM the catalog task need to be created and also it will be created just once.

find_real_file.png

find_real_file.png

Now the next step is to write another BR on Requested Item table and use the details as shared below:

BR Details:

Table Name: Requested Item

When: After Update

Order : 1000

Condition: Check Reopen Changes to True AND State is Reopen

Script:

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

	// Add your code here
	var getRequest = current.request;
	var gr = new GlideRecord('sc_request');
	gr.addQuery('sys_id',getRequest);
	gr.query();
	if(gr.next()){
		var getRITM = getAllRITM(gr.sys_id,current,gr);
	}
	
	function getAllRITM(reqID,current,gr){
		var gr1 = new GlideRecord('sc_req_item');
		gr1.addQuery('request',reqID);
		gr1.addQuery('u_check_reopen',true);
		gr1.query();
		if(!gr1.next()){
			createCatalogTask(current,gr1);
		}
	}
	
	function createCatalogTask(current,gr1,gr){
		var gr2 = new GlideRecord('sc_task');
		gr2.initialize();
		gr2.request_item = gr1.sys_id;
		gr2.parent= gr1.sys_id;
		gr2.FIELD_NAME = gr1.Field_Name; // Replace "FIELD_NAME" with field of Catalog Task and "Field_Name" with the field of Requested Item table which you want to copy
		gr2.insert();
	}

})(current, previous);

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

7 REPLIES 7

shloke04
Kilo Patron

Hi @RC 

There can be multiple approaches for this scenario. It all depends on how your current setup is done, how are user re open their RITM record, are they using Service Portal for this or a Email which they reply back to?

So generically speaking you can have a Business Rule set up which will take care of both of your requirement:

BR Details:

Table Name: Requested item(sc_req_item)

When: After Update

Condition: State Changes from Resolved AND State Changes TO Reopen

Script:

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

	// Add your code here
	createAdditionTask(current);
	updateRequest(current);
	
	function createAdditionTask(current){
		var gr = new GlideRecord('sc_task');
		gr.initialize();
		gr.request_item = current.sys_id;
		gr.FIELD_name = current.field_name; //Replace "field_name" with the Field of Requested Item and replace "FIELD_name"  with field of Catalog task for setting other field values
		gr.insert();
	}
	
	function updateRequest(current){
		var gr1 = new GlideRecord('sc_request');
		gr1.addQuery('sys_id',current.request);
		gr1.query();
		if(gr1.next()){
			gr1.state = 2; // Change 2 with the value of Work in progress if needed
			gr1.update();
		}
	}

})(current, previous);

 

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

RC10
Tera Contributor

Hi Shloke,

Many thanks for the response.

We tried your suggestion and it's working but it's creating duplicate SCTASK tickets i mean if an user change the RITM state to open for some "n" times then the SCTASk ticket also creating "n" times, As per the requirement we need to create the SCTASK only once.

And as i mentioned above currently TWO RITM tickets are creating under one REQ.

we need to check which RITM is reopened first then we need to create the SCTASK under the reopened RITM ticket.

if later another RITM is reopened then we no need to create the SCTASK.

ANd could you pls check the below script once because the RITM number is not coping from the RITM to SCTASk ticket.

Advance thanks for the support.

 

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

// Add your code here
createAdditionTask(current);
updateRequest(current);

function createAdditionTask(current){
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request_item = current.sys_id;
gr.parent = current.number;   // the RITM number coping line
gr.parent = current.request;
gr.assignment_group = '123d456sdfg';
gr.approval = current.approval;
gr.u_cat_1 = current.u_cat_1;
gr.u_cat_2 = current.u_cat_2;
gr.u_cat_3 = current.u_category_3;
gr.u_cat_4 = current.u_category_4;
gr.short_description = 'Create a List';
gr.description = 'Create a List';

gr.insert();
}

function updateRequest(current){
var gr1 = new GlideRecord('sc_request');
gr1.addQuery('sys_id',current.request);
gr1.addQuery('request_state','Resolved'); // Added Resolved becuase we need to change the REQ state only when it's in Resolved
gr1.query();
if(gr1.next()){
gr1.request_state = Work in Progress; // Change 2 with the value of Work in progress if needed
gr1.update();
}
}

})(current, previous);

Hi @RC 

In that case you need to follow the steps below and then do it:

1) First create a hidden field on Requested Item Table say name it as "Check Reopen" and type of the field will be as "True/False" as shown below:

find_real_file.png

2) Now create a Before Update business Rule as per details shared below:

BR Details:

Table Name : Requested Item

When: Before Update

Condition: State Changes to Reopen and Check Reopen is False

Script:

This BR will set the value of the hidden field to True only once when any of the RITM is moved to Reopen. So using this you can identify for which RITM the catalog task need to be created and also it will be created just once.

find_real_file.png

find_real_file.png

Now the next step is to write another BR on Requested Item table and use the details as shared below:

BR Details:

Table Name: Requested Item

When: After Update

Order : 1000

Condition: Check Reopen Changes to True AND State is Reopen

Script:

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

	// Add your code here
	var getRequest = current.request;
	var gr = new GlideRecord('sc_request');
	gr.addQuery('sys_id',getRequest);
	gr.query();
	if(gr.next()){
		var getRITM = getAllRITM(gr.sys_id,current,gr);
	}
	
	function getAllRITM(reqID,current,gr){
		var gr1 = new GlideRecord('sc_req_item');
		gr1.addQuery('request',reqID);
		gr1.addQuery('u_check_reopen',true);
		gr1.query();
		if(!gr1.next()){
			createCatalogTask(current,gr1);
		}
	}
	
	function createCatalogTask(current,gr1,gr){
		var gr2 = new GlideRecord('sc_task');
		gr2.initialize();
		gr2.request_item = gr1.sys_id;
		gr2.parent= gr1.sys_id;
		gr2.FIELD_NAME = gr1.Field_Name; // Replace "FIELD_NAME" with field of Catalog Task and "Field_Name" with the field of Requested Item table which you want to copy
		gr2.insert();
	}

})(current, previous);

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke