UI Acton use case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have to create a new UI Action on incident form named as Submit. Expected behaviour should be like it should check if there is an existing active/open (anything above resolved) ticket for the same caller with same category and subcategory. If so, flag it as a duplicate and convey to the caller that existing ticket with same category and subcategory already exists, hence you're not allowed to create a new ticket. Do not use alert, use info message (form header menu type) instead, and Color coding of this info message should be red. Show the existing ticket number in the info message and the number should be a hyperlink, on clicking which the caller should be redirected to that existing incident record in a new tab.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @radhikania ,
Please try below.
Create a new UI action and hide existing one.
Name: Submit
Table: Incident
Action name: submit_check_duplicates
Form button: Checked
Show Insert: Checked
Show Update: Unchecked
Client: Unchecked
Condition: current.canCreate()
The Script:
(function() {
// 1. DEFINE THE DUPLICATE CHECK CRITERIA
var grIncident = new GlideRecord('incident');
grIncident.addQuery('caller_id', current.caller_id);
grIncident.addQuery('category', current.category);
grIncident.addQuery('subcategory', current.subcategory);
// 2. DEFINE "ACTIVE/OPEN"
// We exclude Resolved (6), Closed (7), and Canceled (8).
// Adjust these numbers if your instance uses different state values.
grIncident.addQuery('state', 'NOT IN', '6,7,8');
grIncident.query();
if (grIncident.next()) {
current.setAbortAction(true);
var existNum = grIncident.getValue('number');
var existSysId = grIncident.getUniqueValue();
// Construct the URL
// 'incident.do' opens the form. target="_blank" forces a new tab.
var linkURL = 'incident.do?sys_id=' + existSysId;
// Create the HTML Hyperlink
// We style it to ensure visibility against the red error background
var linkHTML = '<a href="' + linkURL + '" target="_blank" style="text-decoration: underline; font-weight: bold;">' + existNum + '</a>';
// Construct the Message
var message = "An existing ticket (" + linkHTML + ") with the same Category and Subcategory already exists for this Caller. You are not allowed to create a new ticket.";
// Display the RED header message (accepts HTML)
gs.addErrorMessage(message);
action.setRedirectURL(current);
} else {
var newSysId = current.insert();
if (newSysId) {
gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);
}
}
})();
Regards,
Vishal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Here is the solution of the Use Case you have given,
UI Action :
Code :
Here is the Result :Here is the existing Record