Issue with UI Action

Sathwik1
Tera Expert

Sathwik1_0-1766075086200.png

My UI Action is not working in the workspace... can someone please guide what I need to write in the workspace client script?

 

@Ankur Bawiskar  @Dr Atul G- LNG 

7 REPLIES 7

@Sathwik1 

any update to this?

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

Deepak Shaerma
Mega Sage

Hi @Sathwik1 

Replace the code in the Workspace Client Script field (bottom box) with this:

function onClick(g_form) {
    // 1. Clear previous error messages
    g_form.hideFieldMsg('close_notes');
    g_form.hideFieldMsg('resolution_code');

    var isValid = true;

    if (g_form.hasField('resolution_code') && g_form.getValue('resolution_code') == "") {
        g_form.showFieldMsg('resolution_code', 'Resolution code is required.', 'error');
        isValid = false;
    }

    if (g_form.hasField('close_notes') && g_form.getValue('close_notes') == "") {
        g_form.showFieldMsg('close_notes', 'Resolution notes are required.', 'error');
        isValid = false;
    }

    if (!isValid) {
        g_form.addErrorMessage('To close a case, you must select a resolution code and add resolution notes.');
        return; // This stops the submit from happening
    }
    g_form.submit('resolve_case');
}


not need to change the Server Side code (lines 19+ in your screenshot). Once g_form.submit() runs successfully, it will trigger that server code automatically.

Happy to help! ‌‌
To help others in the community find this solution, kindly mark this response as the Correct Answer ‌‌ and Helpful‌‌.
Warm Regards,
Deepak Sharma
Community Rising Star 2025


Return should not be used in the client side.. it blocks some other OOB UI Action.

Open the respective table.. and from form header. right click on it.. it wont work.