Convert Incident into request item

Gautam Gattu
Mega Expert

Business requirement1. Convert INC to RITM2. Once converted INC ticket should be cancelled and have reference of RITM.3. INC fields details should be mapped with RITM fields (attached screen shot for mapping fields)

============================================================================

Created UI policy

var you_are_elle_path = 'sc_req_item.do?sysparm_incident_id=' + current.sys_id;
action.setRedirectURL(you_are_elle_path);

current.active = false;
current.state = 8; // cancelled state
current.updateWithReferences();

function createRITM() {
    var ritm = new GlideRecord("sc_req_item");
    ritm.initialize();
    ritm.company = current.company;
    ritm.u_req_for = current.caller_id;
    ritm.u_request_type = current.u_issue_type;
    ritm.assignment_group = current.assignment_group;
    ritm.configuration_item = current.cmdb_ci;
    ritm.short_description = current.short_description;
    ritm.description = current.description;
    ritm.work_notes = current.work_notes;
    ritm.comments = current.comments;
    ritm.state = '1';
    ritm.priority = current.priority;
    ritm.watch_list = current.watch_list.getDisplayValue().toString();
    ritm.parent = current.sys_id;
    ritm.insert();
    //return ritm;

    gs.addInfoMessage("Incident has cancelled, Requested Item " + ritm.number + " created.");
    action.setRedirectURL(ritm);
    action.setReturnURL(current);
}

Assistance needed

1. RITM fields does not have INC fields data

2. INC is getting closed however no reference of RITM

1 ACCEPTED SOLUTION

Gautam Gattu
Mega Expert

I achieve the business requirement by using below code:

===========================================================

var you_are_elle_path = 'sc_req_item.do?sysparm_incident_id=' + current.sys_id;
action.setRedirectURL(you_are_elle_path);
var incnumber = current.number;
current.active = true;
current.state = 8;
current.close_code = "Converted to Request Ticket";
current.updateWithReferences();

var ritm = new GlideRecord("sc_req_item");
var ritmnumber = current.number;
ritm.company = current.company;
ritm.u_parent_number = incnumber;
ritm.u_req_for = current.caller_id;
ritm.u_request_type = current.u_issue_type.getDisplayValue();
ritm.assignment_group = current.assignment_group;
ritm.configuration_item = current.cmdb_ci;
ritm.short_description = current.short_description;
ritm.description = current.description;
ritm.work_notes = current.work_notes;
ritm.comments = current.comments;
ritm.state = '1';
ritm.priority = '4';
ritm.watch_list = current.watch_list.getDisplayValue().toString();
ritm.insert();

current.close_notes = "This incident qualifies to be a request, hence incident has cancelled and converted into Requested Item " + ritm.number.getDisplayValue();

current.update();
action.setRedirectURL(ritm);

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Gautam,

can you update code as below; ensure you use proper field on incident table to store the ritm reference

createRITM();

function createRITM() { 

 var ritm = new GlideRecord("sc_req_item");
    ritm.initialize();
    ritm.company = current.company;
    ritm.u_req_for = current.caller_id;
    ritm.u_request_type = current.u_issue_type;
    ritm.assignment_group = current.assignment_group;
    ritm.configuration_item = current.cmdb_ci;
    ritm.short_description = current.short_description;
    ritm.description = current.description;
    ritm.work_notes = current.work_notes;
    ritm.comments = current.comments;
    ritm.state = '1';
    ritm.priority = current.priority;
    ritm.watch_list = current.watch_list.getDisplayValue().toString();
    ritm.parent = current.sys_id;
    ritm.insert();
	
	
	current.active = false;
	current.state = 8; // cancelled state
	current.<incidentField> = ritm.sys_id;
gs.addInfoMessage("Incident has cancelled, Requested Item " + ritm.number + " created.");
		

	action.setRedirectURL(ritm);
    action.setReturnURL(current);
	
	}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

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

Did not work.

Hi Gautam,

can you share updated script? Also do you have field on incident to store RITM value?

Is it not creating RITM? or is it creating RITM but not redirecting or populating the value in incident? Is it not updating incident with closed

Regards

Ankur

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

With my initial code I could achieve following:

1. Incident is getting closed

2. RITM is getting created

Yet to be acheive

1. Post incident closer, RITM ticket number to be added in INC.

2. Field mapping is not working along with incident ticket history in RITM.