how to limit the character on the multi line text catalog variable?

Mada11
Tera Contributor

Hi,

how to limit the character on the multi line text catalog variable?

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Mada11 

you will have to write onChange client script on that variable and validate

you cannot give anything in variable attributes in catalog

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

Mada11
Tera Contributor

Hi Ankur,

Tried this but it doesnot work;

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var currentLength = newValue.length;
if (currentLength > 10) {

newValue = newValue.substring(0, 10);
g_form.setValue("name", newValue);
g_form.showFieldMsg("name", "Maximum entry is 10 characters.!",'error');
}
}

@Mada11 

what debugging did you do?

Update as this to hide the field message whenever onchange runs

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
	g_form.hideFieldMsg('name');
    var currentLength = newValue.length;
    if (currentLength > 10) {
        newValue = newValue.substring(0, 10);
        g_form.setValue("name", newValue);
        g_form.showFieldMsg("name", "Maximum entry is 10 characters.!", 'error');
    }
}

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

@Mada11 

Thank you for marking my response as helpful.

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