The CreatorCon Call for Content is officially open! Get started here.

Prevent update via UI action

MarkNow
Giga Contributor

Hi, I'm trying to prevent incident submissions with short descriptions (less than 10 characters) using a UI Action script. I've created the script to show an error message and prevent submission, but it's not working as intended. When I click Submit, the incident still opens even if the description is too short.

I've tried using a Client Script, and that works correctly. Is there a way to achieve this using a UI Action?

Additionally, I'd like to add two empty lines after the error message within the same frame. Is this possible?

Any help would be greatly appreciated

4 REPLIES 4

Hemanth M1
Giga Sage
Giga Sage

Hi @MarkNow ,

 

Can you share the UI Action scrript here???

you must use return false; if u r validation is in client side or use current.setAbortAction(true); if its in the Server side logic.

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

 
function onSubmit() {
    var field = g_form.getValue('short_description');
    if (short_description.length < 10) {
        g_form.showFieldMsg('short_description', 'The title is too short (less than 10 characters).'
        g_form.showFieldMsg('short_description', 'Please complete', 'error');
    }
    return false; // Prevent submission
}

Hi @MarkNow ,

There are erros in your code, here is the working code.

1)line number 2 - short_description.length < 10) --> this should be field.length<10

2)Line number 3 bracker is not closed

3)Return false is outside of the if block.

 

Here is the working code.

function onSubmit() {
    var field = g_form.getValue('short_description');
    if (field.length < 10) {
        g_form.showFieldMsg('short_description', 'The title is too short (less than 10 characters).');
        g_form.showFieldMsg('short_description', 'Please complete', 'error');
        return false; // Prevent submission
    }
}

 

Hope this helps!!!

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Community Alums
Not applicable

Hi @MarkNow ,

Please check below script this will help you 

function onSubmit() {
    var field = g_form.getValue('short_description');
    if (field.length < 10) {
        g_form.addErrorMessage('The title is too short (less than 10 characters');
        g_form.addErrorMessage('Please complete');
		return false; // Prevent submission
    }
    
}

SarthakKashyap_0-1723573725203.png

Result 

SarthakKashyap_1-1723573756109.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak