- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2019 06:48 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2019 12:22 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2019 01:00 AM
Hi Allen,
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;
}
For checking if a certain entry of zip code and street is already existing in the database, I use a business rule like this:
// Instantiate the NeedItUtils class. Call the isDatePast method and pass
// the u_when_needed value.
var street = current.strasse;
var plz = current.postleitzahl.getDisplayValue();
// If the combination of street and zip code exists already, display error and about action
if(street == "Vogelstraße" && plz == "60528")
{
gs.addErrorMessage("Kombination von PLZ und Strasse gibt es bereits:"+ plz);
current.setAbortAction(true);
}
Of course this needs to be dynamic, but first I needed to make it work.
Thanks a lot for help.
Best regards,
Frank