I have a requirement to copy incident and but I do not want to insert the record right away. It should create the new incident once click on Save.

balaji_prusty1
Giga Guru

I have a requirement to copy the incident and but I do not want to insert the record right away. It should create the new incident once click on Save.

Currently, the copy incident copies all the previous incident detail and create a new incident. But it sents the notification with old detail whenever the recorded incident as per notification condition.

Please let me know if anyone has a solution to this.

Thanks in Advance.

Balaji Prusty

 

 

 

7 REPLIES 7

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


check this:

https://www.servicenowelite.com/blog/2014/2/24/copy-incident

 

Other idea would be navigate the user to new incident and get all attributes via URL.

https://community.servicenow.com/community?id=community_blog&sys_id=596dea29dbd0dbc01dcaf3231f96190b


Thanks,
Ashutosh

Allen Andreas
Administrator
Administrator

Hello,

The OOB "Copy Incident" UI Action, merely takes some values from the prior incident and opens a blank form with those values populated. It's not inserted or saved.

You all must have changed the UI Action to make the behavior different, or you created your own.

Please give more information as to how you're copying the incident.

For example, this is the OOB UI Action for Copy Incident:

function OnCopyIncidentClick(){
	var srcSysId = g_form.getUniqueValue();
	var ga = new GlideAjax('IncidentUtils');
	ga.addParam('sysparm_name', 'getIncidentQueryParams');
	ga.addParam('sysparm_src_sysid', srcSysId);
	ga.addParam('sysparm_ui_action', "copy_incident");
	ga.setWantSessionMessages(true);
	ga.getXMLAnswer(function(queryParam){
		if (queryParam) {
			var ck;
			if (typeof g_ck != 'undefined' && g_ck != "")
				ck = g_ck;

			var gotoUrl = [];
			gotoUrl.push('srcSysID=' + srcSysId);
			gotoUrl.push('newSysID=$sys_id');
			gotoUrl.push('sysparm_returned_action=$action');
			gotoUrl.push('sysparm_ui_action=copy_incident');
			if (ck)
				gotoUrl.push('sysparm_ck=' + ck);

			gotoUrl = 'CopyIncidentRelatedLists.do?' + gotoUrl.join('&');

			var form = cel('form', document.body);
			hide(form);
			form.method = "POST";
			form.action = g_form.getTableName() + ".do";
			if (ck)
				addParam(form, 'sysparm_ck', g_ck);
			addParam(form, 'sys_id', '-1');
			addParam(form, 'sysparm_query', queryParam);
			addParam(form, 'sysparm_goto_url', gotoUrl);
			form.submit();
		}else{
			g_form.addErrorMessage("Failed to copy incident");
		}
	});
}
function addParam(form, name, val) {
	var inp = cel('textarea', form);
	inp.name = name;
	inp.value = val;
}

With condition:

IncidentUtils.isCopyIncidentEnabled() && ( gs.hasRole('itil,sn_incident_write') || current.caller_id == gs.getUserID() )

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thanks, Allen for the quick response.  Seems this OOB functionality came on the latest version. Earlier it was inserting the ticket in the incident table while copying (below coding). In this latest version any idea how to pass the customized field value?  It seems it copies all the fields of the old incident to the new one. Need to restrict some fields.

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

function runClientCode(){
g_form.setMandatory('u_callback_contact_type', false);
gsftSubmit(null, g_form.getFormElement(), 'Copy_Incident'); //Action name to run business code
}

runBusRuleCode();

function runBusRuleCode(){
var newinc = new GlideRecord('incident');
newinc.initialize();
newinc.short_description = current.short_description;
newinc.work_notes = 'Created from a similar incident: ' + current.number;
newinc.insert();
action.setRedirectURL(newinc);
action.setReturnURL(current);
}

 

Thanks

Hi,

Using the above code, that alone doesn't show that it's copying all the fields. You can see that it's only copying the short description (as is what the OOB one does today as well) and then just leaves a worknote to say that they made a copy of it.

If you wanted to add a few more fields, you could just do:

newinc.field_name = current.field_name;
newinc.field_name2 = current.field_name2;

So you would just add more lines to the script above as you see fit with the precise fields you are trying to also have copied.

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!