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

Cheyenne1
Kilo Guru

My recommendation would be to 'Insert and Stay' to make a copy of the UI Action and then make the changes so you aren't modifying anything OOTB as it could potentially impact future upgrades.

I was planning on creating a copy of the OOB UI Action and modifying the copy, for the exact reason.

 Hi Ian,

 

I was reading this thread and I have a requirement to pass the current Change request number and update the work notes with that number.

Could you please let me know how do I pass the current change request number?

 

I am trying like this and it's printed the comment but couldn't able to pass the current change request number.

 

addParam(form, 'sysparm_query', queryParam + '^u_copied_change=true' +'^work_notes =This Change has been copied from:' + ????????);

Any help will be much appreciated!!!

Hi Ian,

 

I have sorted out.

Though Thank You.

Hello Manish, could you please explain how you managed to achieve this requirement? Please paste the code snippet as I have a similar kind of requirement.

 

Thanks,

Mahesh