"Copy Change" UI Action creates a copied change record but returns the browser to my previous screen

Shant Cancik
Tera Contributor

Hey guys, so I have a "Copy Change" Ui Action in the Change Request table and when I click on it it correctly copies the information from the current record into a new record view. The problem is that when I press "Submit" to submit that new and copied record, my screen returns to the original change record where I clicked on the "Copy Change" UI Action.

I'd rather have it take me to the new submitted change record.

Anyone know how to fix this? Here's the code to the "Copy Change" Ui Action if it helps in any way:

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

  }

  });

}

2 REPLIES 2

shloke04
Kilo Patron

Hi,



This is how the OOB behavior is for Submit button available on the Global Table i.e. It Saves the new Record for you and redirects you back to the Previous screen on which you were working. For example Say if you have Opened a Change Record and clicked on the Copy Change button and now before clicking on the Submit button say you have opened some other page in Service Now and then click on the Submit Button so post click it will redirect you to the page which was opened before the Submit button was clicked.



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Thanks for the reply Shloke,



Interesting because when I create a change record regularly (from the Create New module) I get sent to the list of open change records after hitting submit. My main issue with this is that for my particular case it becomes very confusing for the user. If I was looking at a completed change request and copied the change and then hit submit, I would be returned to the original change record where the user would likely not realize that they are not looking and their newly copied record but still looking at the old one. I guess there's nothing that can be done about this?



-Shant