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

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.

Hi Jonny,

 

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 Jonny,

 

I have sorted out.

Though Thank You.

How are you reading the URL, in the browser the parameter added is not visible. I used GlideUrl API to read that parameter but no luck.