Copy an incident

reeset
Kilo Contributor

Hi, I am trying to create a "copy incident" button that will copy all the completed fields except caller and impacted user to a new incident.   This will be used when we have multiple copies of the same request for different people.   I was able to get te button to display but when I click on it, it doesn't do anything.   Here is my code, any help woul be greatly appreciated.

var newinc = new GlideRecord('incident');

newinc.initialize();
newinc.short_description = current.short_description;
newinc.u_requested_by = current.u_requested_by;
newinc.u_requested_for = current.u_requested_for;
newinc.assignment_group = current.assignment_group;
newinc.assigned_to = current.assigned_to;
newinc.description = current.description;
newinc.u_business_impact = current.u_business_impact;
newinc.category = current.category;
newinc.u_service_affected = current.u_service_affected;
newinc.u_service_impact = current.u_service_impact;
//newinc.incident_state = current.incident_state;
newinc.severity = current.severity;
newinc.impact = current.impact;
newinc.priority = current.priority;


newinc.insert();

gs.addInfoMessage('Incident ' + newinc.number + ' created.');
action.setRedirectURL(newinc);
action.setReturnURL(current);

find_real_file.png

2nd shot below is picture of form with button on it

find_real_file.png

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

For your reference, this works.. Attaching the xml of the ui action and a screenshot for your reference


View solution in original post

8 REPLIES 8

Michael Fry1
Kilo Patron

Why don't you make a copy of 'Insert & Stay" UI Action and call it Copy Incident, make it a button.



Then add your 2 lines of code 'current.caller_id = ''; current.impacted_user = ''; (not sure the correct field name but you get the idea) before the current.insert();



done


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Terry Reese



You could refer the below post as a reference.


https://community.servicenow.com/message/670531#670531


On clicking copy incident button some of the fields which I script should be copied to the child's incident with new incident number and then i should be able to submit it after filling some of the other fields. because of newinc.insert() function. New form is created before I submit with only some values filled in.


Kalaiarasan Pus
Giga Sage

Remove the statement fron 'onclick' field of the UI action .. Dont make the ui action a client side button(Un check the client checkbox).. Paste the code in script now and check...