How to terminate the string characters in service now

String
Kilo Sage

Hi Team,

we trying to restricting the use for 20 characters for note field ,So we written client script onChange .we need to stop typing after 20 character and show an alert .but user  enter more than 20 characters also ,Script not showing any alert 

 

Below Is my code :

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {

        return;

   var dec = g_form.getValue('notes');

// Calculate the byte length of the string using TextEncoder

    var byteLength = new TextEncoder().encode(dec).length;

 if (byteLength > 20) {

       alert("notes length exceeds 4000 bytes');

        return false;

    }}

Please guide me 

5 REPLIES 5

Hi @String ,

 

The other way would be via DOM Manipulation which we cannot suggest. Also not a good practice. So whatever solution suggested by fellow community experts plz go with that.

 

Thanks,

Danish