How to redirect to change form from incident create change option

AmitK1382912422
Tera Contributor

Whenever i click on create change option in incident form the below dialog box coming up but it should redirect to the 2nd snip change for instead of dialog box. can anyone suggest how to achieve it. Thanks in advance


AmitK1382912422_0-1781793426011.jpeg

2nd snip:

AmitK1382912422_1-1781793485781.png

 

 

1 REPLY 1

mza-guille
Giga Contributor

Hi Amit,

The dialog is expected OOB behavior for the Create Change option, because ServiceNow uses it to decide what kind of Change flow/model should be started.

If your requirement is to skip that dialog and open the Change Request form directly, I would not modify the OOB UI Action directly. Create a new UI Action or copy the existing one, then redirect to the new Change form.

If you want to open a new Change form without saving it immediately, use a redirect like this:

var url = new GlideURL('change_request.do');
url.set('sys_id', '-1');
url.set('sysparm_query', 'parent=' + current.sys_id + '^short_description=' + current.short_description);
action.setRedirectURL(url.toString());

That opens the Change form and pre-populates values from the Incident.

If you want the Change to be created immediately and then redirect the user to the created Change record, use this pattern instead:

var chg = new GlideRecord('change_request');
chg.initialize();
chg.parent = current.sys_id;
chg.short_description = current.short_description;
chg.description = current.description;
chg.cmdb_ci = current.cmdb_ci;
var chgSysId = chg.insert();
if (chgSysId) {
    action.setRedirectURL(chg);
}

So the decision is:

  • Need user to review/edit before save: redirect to change_request.do with sys_id=-1.
  • Need to create the Change immediately: insert the change_request and use action.setRedirectURL(chg).

Also check whether your instance is using Change Models / Change Interceptor. If it is, bypassing the dialog may skip some OOB logic, so test it with Normal/Emergency/Standard Change before replacing the existing button.