Disable UI Action

aamir khan
Tera Contributor
Dear Members, 
 
We have OnClick UI action on Incident record & below is the script which return the Ticket to Helpdesk group whenever required and then helpdesk agent transfer the ticket to other group.
 
We need to limit this UI Action in such a way that if the the ticket already returned 5 times to Helpdesk group. This UI Action should be freeze or disappear from the ticket so the ticket cannot be return anymore. 
 
Please advise in the script what to add to achieve this case. 
 
Script:
 
function ReturnToHelpdesk() {
    if (g_form.getValue("work_notes") == "") {
        g_form.setMandatory("work_notes", true);
        g_form.clearMessages();
g_form.setValue('state',1);
        getMessage("Work Note", function(msg) {
            g_form.addErrorMessage(msg, "error");
        });
    }
    gsftSubmit(null, g_form.getFormElement(), 'Return_To_Help_Desk'); 
}
 
if (typeof window == 'undefined')
    Default();
 
function Default() {
    var GroupName = gs.getProperty('Help Desk');
    current.assignment_group = GroupName;
    current.update();
    action.setRedirectURL(current);
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@aamir khan 

you need to have a custom integer type field to store the count and then increment it from server side each time button is clicked

UI Action condition

Your Existing UI Action Condition && current.u_count <= 5

Script Update

function Default() {
    var GroupName = gs.getProperty('Help Desk');
    current.assignment_group = GroupName;
    current.u_count = current.u_count + 1;
    current.update();
    action.setRedirectURL(current);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Abhijeet_Pawar
Tera Guru

Hello @aamir khan ,

Please create a Script Include that accepts the current record’s sys_id as an input. Inside the Script Include, use the Glide Audit History table to check how many times the Assignment Group was set to "Help Desk"based on sys_id of record.

If the count is 5 or more, return false; otherwise, return true.

Then, call this Script Include from the "Condition" field of the UI Action. Based on the returned value:

  • If true, the button will be visible.

  • If false, the button will be hidden.

Please try this approach — it should work as expected.

Thank you

Shubham_Jain
Mega Sage

@aamir khan 

Here is proposed solution from my end: 

1. Use a custom counter field - This avoids relying on logs or history.

2. Update the UI Action Logic 

3. Add the condition to UI Action - This will help to hide the button automatically once the limit is reached. 

 

 

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain


Ankur Bawiskar
Tera Patron
Tera Patron

@aamir khan 

you need to have a custom integer type field to store the count and then increment it from server side each time button is clicked

UI Action condition

Your Existing UI Action Condition && current.u_count <= 5

Script Update

function Default() {
    var GroupName = gs.getProperty('Help Desk');
    current.assignment_group = GroupName;
    current.u_count = current.u_count + 1;
    current.update();
    action.setRedirectURL(current);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@aamir khan 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader