UI Action to redirect incident.do page with auto populate fields

AnilM99
Tera Expert

Hi Team,

 

I created UI action (Create Inc) on RITM 

If we click on Create Inc then it should redirect's to Incident.do page with auto populate fields of RITM.

Ex.

Caller = Assigned to

Short description = short description

Description = description

Priority = Priority 

Assignment group = Assignement group

 

Help me on the Same

Thanks Anil!

 

1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage
Mega Sage

Hi @AnilM99 ,

 

Create an UI action form button, select the 'client checkbox' and mention the onclick function, you can copy the below script, it should work

KaranChhabra6_0-1682970238052.png

KaranChhabra6_1-1682970948915.png

 

UI Action script

function openIncident() {

    var query = 'caller_id=' + g_form.getValue('assigned_to') + '^short_description=' +  g_form.getValue('short_description') + '^description=' + g_form.getValue('description') + '^priority=' + g_form.getValue('priority') + '^assignment_group=' + g_form.getValue('assignment_group');
    var url = new GlideURL('incident.do');
    url.addParam('sys_id', '-1');
    url.addParam('sysparm_stack', 'no');
    url.addParam('sysparm_query', query);
    var w = getTopWindow();
    var newWindow = w.open(url.getURL(), "_blank");
    newWindow.focus();

}

 

If my answer has helped with your question, please mark it as helpful and accepted solution.

 

Thanks,

Karan

 

 

View solution in original post

5 REPLIES 5

Bert_c1
Kilo Patron

Hi,

 

add:

 

action.setRedirectURL(current);

 

To you UI action script at the end, and use a value of the desired URL. See similar UI Actions in your instance

 

https://[instnace_name].service-now.com/sys_ui_action_list.do?sysparm_query=scriptLIKEredirect%5Esys...

 

URL will be like what is in your browser address when you are viewing an incident

 

https://[instance_name].service-now.com/nav_to.do?uri=incident.do?sys_id=9e7f9864532023004247ddeeff7...

 

Karan Chhabra6
Mega Sage
Mega Sage

Hi @AnilM99 ,

 

Create an UI action form button, select the 'client checkbox' and mention the onclick function, you can copy the below script, it should work

KaranChhabra6_0-1682970238052.png

KaranChhabra6_1-1682970948915.png

 

UI Action script

function openIncident() {

    var query = 'caller_id=' + g_form.getValue('assigned_to') + '^short_description=' +  g_form.getValue('short_description') + '^description=' + g_form.getValue('description') + '^priority=' + g_form.getValue('priority') + '^assignment_group=' + g_form.getValue('assignment_group');
    var url = new GlideURL('incident.do');
    url.addParam('sys_id', '-1');
    url.addParam('sysparm_stack', 'no');
    url.addParam('sysparm_query', query);
    var w = getTopWindow();
    var newWindow = w.open(url.getURL(), "_blank");
    newWindow.focus();

}

 

If my answer has helped with your question, please mark it as helpful and accepted solution.

 

Thanks,

Karan

 

 

Thanks for the reply @Karan Chhabra6,

The code is working perfectly, but I need to map one more field called - RITM Number 

AnilM99_0-1683036873105.png

Help me on the same

Thanks Anil!

 

 

Amit Gujarathi
Giga Sage
Giga Sage

Hi @AnilM99 ,
I trust you are doing fine.

To achieve this functionality, you can create a UI action on the RITM form that redirects to the Incident form with pre-populated fields.

Here's an example code snippet that should help you get started:

function createIncidentFromRITM() {
  var current = g_form.getTableName();
  var ritmSysId = g_form.getUniqueValue();
  var url = "https://your-instance.service-now.com/incident.do";

  // add the RITM sys_id to the URL
  url += "?sysparm_query=ritm=" + ritmSysId;

  // set the Caller field to the current user
  var currentUserSysId = g_user.userID;
  url += "&caller_id=" + currentUserSysId;

  // set the Short description field to the RITM's short description
  var shortDescription = g_form.getValue("short_description");
  url += "&short_description=" + encodeURIComponent(shortDescription);

  // set the Description field to the RITM's description
  var description = g_form.getValue("description");
  url += "&description=" + encodeURIComponent(description);

  // set the Priority field to the RITM's priority
  var priority = g_form.getValue("priority");
  url += "&priority=" + encodeURIComponent(priority);

  // set the Assignment group field to the RITM's assignment group
  var assignmentGroup = g_form.getValue("assignment_group");
  url += "&assignment_group=" + encodeURIComponent(assignmentGroup);

  // open the new incident form in a new window
  window.open(url, '_blank');
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi