- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2023 11:57 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2023 12:57 PM
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2023 12:38 PM - edited 05-01-2023 12:42 PM
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
URL will be like what is in your browser address when you are viewing an incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2023 12:57 PM
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 07:15 AM
Thanks for the reply @Karan Chhabra6,
The code is working perfectly, but I need to map one more field called - RITM Number
Help me on the same
Thanks Anil!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 07:18 AM
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