Variable Attribute max length issue

Cupcake
Mega Guru

Good morning all,

        I have two things that I am trying to solve for:

1.         I am trying to set one of my catalog variable to a max length of 9. I've done this for other variables but it seems for some reason that it is not holding the max_length=9. Even though I               change the view to get to the variable attributes and I save it after I've entered the max length, the system is not holding what I've put in.

2.         Also is there a way to make that same variable ONLY 9 characters. Meaning the customer doesn't want any less than 9 characters or any more than 9 characters.

find_real_file.png

Thank you,

Karen

1 ACCEPTED SOLUTION

larstange
Mega Sage
  1. Try and add variable attributes as a column in the variables table on the parent catalog item and change the value through the table
  2. You have to enforce the 9 characters via an onChange / onSubmit client script where you display some sort of error if anything less than 9 character have been entered


E.g. an onSubmit CS:



var routing = g_form.getValue('dd_routing_number1');


if (routing.length != 9) {


alert('You must enter 9 characters');


return false;


}


View solution in original post

8 REPLIES 8

Deepa Srivastav
Kilo Sage

You can use below:



    if (current.variables.urfield_id.toString().length != 9) {


g_form.addErrorMessage('max length should be 9');


        }



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


Chuck Tomasi
Tera Patron

According to the wiki, it should work.



See section 21 here. Variable Types - ServiceNow Wiki



Have you tried other values?




If you want to ensure you have 9 and only 9 characters, An onSubmit client script could do a quick character count and abort. Something like:



function onSubmit(control, oldValue, newValue, isLoading) {


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


          return;


    }



  if (current.newValue.length != 9) {


        g_form.addErrorMessage('9 characters only please.')


        return false;


  }


}



This script is untested.



http://wiki.servicenow.com/index.php?title=Client_Scripts


xiaix
Tera Guru

Very lame that this happens.  It's absurd that you can't set max_length, and that you'd need to rely on an onSubmit script to handle it.

So, I personally get the maxlength attribute set by manipulating the DOM via an SP widget:

I have a Single Line Text field named "upc" as a Catalog Item Variable.

 

find_real_file.png

find_real_file.png

find_real_file.png

Christian Engs2
Giga Contributor

Hi 

I solved it with a little onload client jquery script:

 

function onLoad() {
  setTimeout(function() { 
    jQuery('input[name="problem.short_description"').attr("maxlength","100"); 
  }, 1000); 
}

 

find_real_file.png