UI Acton use case

radhikania
Giga Contributor

 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.

2 REPLIES 2

Vishal_Jaiswal
Mega Guru

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

Here is the solution of the Use Case you have given,
UI Action :
Screenshot 2025-11-27 100906.png

Code :

Screenshot 2025-11-27 100848.png

 

Here is the Result :
1234.pngHere is the existing Record
1233.png