Incident Short Description Max Length Limit Not Honored?

brianlarue
Kilo Contributor

I would like to limit the number of characters entered in the Short Description field on the Incident form. Here's what I've tried:

Within the Form Designer, in the Short Description field properties (accessed by clicking the gear icon), there is an option for "Max Length." I have modified this to a more desirable number, e.g. 100, and saved the form. After reloading the form, it appears that this value has been reset to the 255 value. Why does this not accept the change? I imagine this can be accomplished by some client-side javascript although I am a new SNow admin. What are my options?

I hesitate modifying the data dictionary on the field in the database due to data loss.

1 ACCEPTED SOLUTION

Hey Brian,



Just switch the order of the functions, first setValue, then showFieldMessage .



Two advices, before the if statement do a hideFieldMessage to remove the text in case the user used less than 80 characters. The other one is to use info instead of error. You will be trimming the description, that means that the user can continue with his work. I don't like leaving red messages if the user doesn't need to modify anything.


View solution in original post

13 REPLIES 13

Hey Brian,



Are you testing this in Service Portal or in the regular instance? To have my client scripts working in Service Portal, I had to modify the UI type. Isn't that CS working? Is it doing something, or it's just not trimming the description? In that case, do you have any errors or warnings in the log?


I'm testing this in our development instance on the "new incident" form--not the Service Portal.



I know it runs because I've added an alert("I'm running") and it did pop-up. It doesn't truncate the characters past the maximum allowed amount and no error box is displayed.



The only error in the javascript console is "Failed to load resource: the server responded with a status of 404 (Not Found)" although, i'm not sure it's related.


Hey Brian,



The issue is that you are not calling properly the function


find_real_file.png



Within getReference, you should add parenthesis to the function. Instead of "checkLimit", put "checkLimit()".



When calling the function, you are sending a variable that doesn't exist. Instead of "field", put "shortDescription".



I tried it in my personal instance and it worked (just the trimming). I used the following script:



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


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


          return;


  }



var sd = g_form.getReference('short_description', checkLimit());




  //Type appropriate comment here, and begin script below



}




function checkLimit(sd){


var sdval = g_form.getValue('short_description');


var maxLength = 8;


if (sdval.length > maxLength){


g_form.setValue('short_description', sdval.substring(0,maxLength));


}


}



Let me know if this work for you.


Thank you. My syntax was wrong and that fixed the truncation of characters. However, I still cannot get the showErrorBox or showFieldMsg methods (I've tried both) to display a notice when the limit has been exceeded. Odd that it would skip the line. It appears that I'm following the correct API call. Am I doing something stupid (again)?



Capture.JPG


Hey Brian,



Just switch the order of the functions, first setValue, then showFieldMessage .



Two advices, before the if statement do a hideFieldMessage to remove the text in case the user used less than 80 characters. The other one is to use info instead of error. You will be trimming the description, that means that the user can continue with his work. I don't like leaving red messages if the user doesn't need to modify anything.