How to edit 'Copy Change' UI Action

bhoomikabisht
Kilo Expert

Hi Experts,

I am working on Change management and want to modify 'Copy Change' UI Action

As per the requirement I want to copy two custom fields which i added added in the form. But I am not getting where to add the code in the UI Action. I checked the script include ChangeUtils. But not getting it.

Please help where i can modify.

Below is the UI Action:

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);

  addParam(form, 'sysparm_goto_url', gotoUrl);

  form.submit();

  }

  });

}

Below is the Script Includes:

var ChangeUtils = Class.create();

ChangeUtils.prototype = Object.extendsObject(ChangeUtilsSNC, {

  initialize: function(request, responseXML, gc) {

  ChangeUtilsSNC.prototype.initialize.call(this, request, responseXML, gc);

  },

  /***************************

  *

  *Add customer changes below

  *

  ****************************/

  type: 'ChangeUtils'

});

/********************************************************************

*The function below is written in this way to provide access via the

*signature ChangeUtils.isCopyChangeEnabled() from UI Action -

*'Copy Change' > Condition.

*

*Customers are suggested to override methods inside the body of

*ChangeUtils' object definition.

********************************************************************/

ChangeUtils.isCopyChangeEnabled = function(current) {

  var changeUtils = new ChangeUtils();

  if (changeUtils.isCopyFlagValid() && changeUtils.isCopyRulesValid(current)) {

  return true;

  } else {

  return false;

  }

};

Thanks & Regards,

Bhoomika Bisht

14 REPLIES 14

Steven Young
Tera Guru

1.   There should be an OOB UI Action to Copy Change   ("Copy Change")    


Name:   Copy Change


Table:   Change Request


Order: 100


Action Name:   copy_change_request


Active:   True


Show Update: True


Client: True


Form Button: True


Comments:   Copies current change record and redirects to the new unsaved change
Onclick:   OnCopyChangeClick()


Condition:   gs.hasRole('itil') && ChangeUtils.isCopyChangeEnabled(current)


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);


  addParam(form, 'sysparm_goto_url', gotoUrl);


  form.submit();


  }


  });


}





So if this is active:   in your application menu on the left side.   look for your "Change Properties"
find_real_file.png





You then have a comma separated list that you can add fields to that you want to be "copied" over to the new record.



find_real_file.png


Steve,


You just cured my headache!!


Thanks for the tip.


John


I also found that the copy change ui action does a lot more than copy the change.


it also coppies the tasks associated the parent change.



so if you copy a change that has 2 chgtasks,   then your new change will have the NEW created tasks, plus the 2 copied tasks.


Then if you copy that change,   you'll have the previous 4 and the new ones.



There is a hidden property that you need to edit.



If you're like us,   you have a change workflow that automates the task creations or whatever.



so to add more properties to your Change management properties page:



1.   type categories in the application menu search (top left)


2. Click "Properties"   under the System Properties application


3. Find the "Change Management"   category


4. then click the Edit button.


in the collection   type   *change_request



add all of the properties to the right and click save.



find_real_file.png



The property you are looking for is:   com.snc.change_request.copy.related_lists
find_real_file.png



the other property is:   com.snc.change_request.copy.rl.change_task.attributes


This is the one that says what change tasks items to copy.



find_real_file.png




i have personally found out that by clearing both of these properties, it creates a brand new change like we want it.





Default Properties Page:


find_real_file.png




Ours after i added the rest of them:


find_real_file.png


Ok, I owed you a beer before, Steve. Now I owe you a case of Heineken! You ROCK. 😉


I created UI action “Copy Change” Under Change form in Table :“Change_Request”.
If we have to send notification for any informational Change, I need to click on “Send change notification under the related link. Post sending when I click on “ Copy Change” under the related link, Only Description and Short Description getting copied, Impact field is not getting copied.[ This Impact field is not in Change_Request Table] , It is under “Change Request Notification”.How can I Copy this?