Need a Script for clone an incident record?

Siddiqbasha
Tera Contributor
 
3 REPLIES 3

HIROSHI SATOH
Mega Sage

There is a copy of the incident OOTB.

HIROSHISATOH_0-1725101851937.png

 

PrashantLearnIT
Giga Sage

Hi @Siddiqbasha 

 

Here is sample script -

 

// Business Rule or UI Action Script

(function() {
// Get the current incident record
var currentIncident = current;

// Create a new incident record
var newIncident = new GlideRecord('incident');
newIncident.initialize();

// Copy fields from the current incident to the new incident
newIncident.short_description = currentIncident.short_description + ' - Clone';
newIncident.description = currentIncident.description;
newIncident.category = currentIncident.category;
newIncident.subcategory = currentIncident.subcategory;
newIncident.priority = currentIncident.priority;
newIncident.urgency = currentIncident.urgency;
newIncident.impact = currentIncident.impact;
newIncident.assignment_group = currentIncident.assignment_group;
newIncident.assigned_to = currentIncident.assigned_to;
newIncident.caller_id = currentIncident.caller_id;
newIncident.contact_type = currentIncident.contact_type;
newIncident.state = currentIncident.state;
newIncident.location = currentIncident.location;
newIncident.u_custom_field = currentIncident.u_custom_field; // Example of a custom field

// Save the new incident record
newIncident.insert();

// Optional: Redirect the user to the new incident record
action.setRedirectURL(newIncident);

})();

 

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

var currentIncident = current;

 

what  I have to change here.