String length in a Business Rule

Frank Eck2
Kilo Contributor

Hi,

from a beginner a very basic question. I want in a business rule to check the length of a string entered (I wouldn't like to do that via UI) and check if it has a certain length.

So I tried the Javascript function like this:

var zipvalue = current.zip_code.length;

But it doesn't deliver anything back. I also tried:

    var zipvalue = current.zip_code;
    zipi = zipvalue.length;

I'm for sure to blond as we say here and my fault is obvious, sadly not to me 😞

Any advice from the community please?

Thanks,

Frank

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

If you're trying to pull this from the sys_user table it's 'zip' not 'zip_code'.

If you're pulling this from a custom field you made then it's u_zip_code? ..just guessing.

But....to get the length you need to get it to string.

So it would be something like:

var zipLength = current.zip.toString().length;

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

johansec
Tera Guru

Couple tips

  1. You can log the value using gs.log(current.zip_code) and make sure you are getting a value.
  2. It is possible you wont get the value without adding .toString() on the end.
  3. So try current.zip_code.toString().length
  4. If the log doesnt return a value double check to make sure that the field name is correct. 
  5. Check you conditions for the business rule to make sure this is running on update. 

Prateek kumar
Mega Sage

What should happen if the length is higher or lower than the expectation.

Should it abort the record creation.?

What type of business rule you configured?


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Hi Prateek,

 

thanks for the support. I found it at the end myself, I wanted to check when submitting the length of a field and if it has a certain length. This I done with a client script now (as said, I'm a beginner).

This is what works now, maybe not most elegant, but it works :-). I guess heavy against any bad practice, but as a starter I need to make it work, beauty contest to follow later if I develop my Javascript skills further :-).

    var zip = g_form.getValue('zip_code');
    var ziplen = zip.length;
    
    if(ziplen != 5)
    
    {
        alert("Länge der Postleitzahl falsch: " + ziplen);
        
        return false;
    }

Allen Andreas
Administrator
Administrator

Hi,

If you're trying to pull this from the sys_user table it's 'zip' not 'zip_code'.

If you're pulling this from a custom field you made then it's u_zip_code? ..just guessing.

But....to get the length you need to get it to string.

So it would be something like:

var zipLength = current.zip.toString().length;

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!