Modifying the Copy Change UI Action

Ian Mildon
Tera Guru

The OOB UI Action Copy Change works very well, especially that it includes all related list items. However, I am trying to figure out how to modify it so that, on the newly created Change, a checkbox is set 'true' to indicate that the UI Action was used to create it.

1 ACCEPTED SOLUTION

jonnygrove
Mega Guru

In the Copy Change UI action, add the name of your true/false field to the line "addParam(form, 'sysparm_query', queryParam);" and set it to true. For me this was line 30:

Example:

addParam(form, 'sysparm_query', queryParam + '^u_custom_field_name=true');

 

Full script:

function OnCopyChangeClick() {
	function addParam(form, name, val) {
		var inp = cel('textarea', form);
		inp.name = name;
		inp.value = val;
	}

	var srcSysId = g_form.getUniqueValue();

	var ga = new GlideAjax('ChangeUtils');
	ga.addParam('sysparm_name', 'getChangeQueryParams');
	ga.addParam('sysparm_src_sysid', srcSysId);
	ga.setWantSessionMessages(true);
	ga.getXMLAnswer(function (queryParam) {
		if (queryParam) {
			var gotoUrl = [];
			gotoUrl.push('srcSysID=' + srcSysId);
			gotoUrl.push('newSysID=$sys_id');
			gotoUrl.push('sysparm_returned_action=$action');

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

			var form = cel('form', document.body);
			hide(form);
			form.method = "POST";
			form.action = g_form.getTableName() + ".do";
			if (typeof g_ck != 'undefined' && g_ck != "")
				addParam(form, 'sysparm_ck', g_ck);
			addParam(form, 'sys_id', '-1');
			addParam(form, 'sysparm_query', queryParam + '^u_copied_change=true');
			addParam(form, 'sysparm_goto_url', gotoUrl);
			form.submit();
		}
	});
}

I added a UI Policy to set the checkbox as Read Only during my testing as well. Looks like you can use this trick for other fields as well.

View solution in original post

15 REPLIES 15

I don't think the Insert and Stay UI action is available OOB on the Change table.

But yes, I agree - make a copy of the Copy Change UI Action and use that instead of the oob one.

Jehiellb
Giga Contributor

Hi guys,

 

I know this is an old post.. This maybe out of the context but just want ask how can I add all the related records when copying a change? 

currently only Affected CIsImpacted Services/CIs, and Change Tasks are able to be copied over to new change.

find_real_file.png

Any idea how can I achieve this? I tried editing the 'Copy Change' UI Action but I failed, nothing happens.
any suggestions what else should I change to make this work? I'm gonna be honest, I'm not that good when it comes to scripting  BUT I'm trying. Maybe you guys can help me with that too. 🙂

 

Just in case you came across with this question, your help will be much appreciated, Thank you in advance!

Hi,

 

Under Change application => Administration => Change properties

In this path have few change related properties are there, it may be helps you to resolve your query please have a look

 

If my answer helps you please click on helpful

 

Jakub4
Mega Contributor

Hi guys, I am currently also editing this copy change functionality and I am bit struggeling to find where to edit the state condition to be enable to create copy also from non-active changes. Any idea? Thanks!

Geoffrey_Bishop
Giga Expert

All, before you update the "Copy Change" UI action, be sure you are familiar with the "Change Properties" management page here:

Change - Administration - Change Properties

That might save you a lot of time.