Adding a reference to original change number when using Copy Change.

tateroth
Giga Contributor

The Change team has made a request to reference the original change number when someone uses the Copy Change UI Action.   I create a field called u_original_change on the change form and made it read only.   I added a snippet of code into the Copy Change UI Action to copy the orginal change number to a variable, but am unsure what code and where to place it to paste it into the new form that is created.   Does anyone have any pointers?

function OnCopyChangeClick() {

  function addParam(form, name, val) {

  var inp = cel('textarea', form);

  inp.name = name;

  inp.value = val;

  }

  var srcSysId = g_form.getUniqueValue();

  //added by T8

  var origChange = g_form.getValue('number');

  //end added by T8

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

  }

  });

}

1 ACCEPTED SOLUTION

Hi,



It seems the UI Action won't help, The value is saved at front end UI but it is not available at database when a new change is copied. You can try adding this before insert business rule with condition as Original Number is empty and script as



current.u_original_change = current.sys_id;


find_real_file.png


find_real_file.png



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response.


View solution in original post

6 REPLIES 6

Alikutty A
Tera Sage

Hi Tate,



The related script include(ChangeUtilsSNC) that copy values are locked by Service Now and I am not sure if there is a way to modify the UI Action. There is a workaround to get this done. Update the u_original_change field with the parent change number and add this field in the system property "com.snc.change_request.copy.attributes".



When change is copied, the value in this field will be copied to the cloned change. Please let me know if it helps.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Thank you, I'm getting closer.   I changed the first part of the Copy Change UI Action to this;



var srcSysId = g_form.getUniqueValue();


  //added by T8


  var origChange = g_form.getValue('number');


  if (g_form.getValue('u_original_change') == "") {


  g_form.setValue ('u_original_change', origChange);


  g_form.save();


  }


  //end added by T8



I also went under Change > Change Properties and added u_original_change to the end of the List of attributes list and Saved.



When I click on Copy Change, it copies the Number to the u_original_change field and saves it, but the new record is still missing the value after it is created.   If the field is populated before the Copy Change command it successfully copies over the value present.   I'm still missing something.


Hi,



It seems the UI Action won't help, The value is saved at front end UI but it is not available at database when a new change is copied. You can try adding this before insert business rule with condition as Original Number is empty and script as



current.u_original_change = current.sys_id;


find_real_file.png


find_real_file.png



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response.


Hi Tate,



Were you able to check this out?



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response