- 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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2019 12:19 PM
Couple tips
- You can log the value using gs.log(current.zip_code) and make sure you are getting a value.
- It is possible you wont get the value without adding .toString() on the end.
- So try current.zip_code.toString().length
- If the log doesnt return a value double check to make sure that the field name is correct.
- Check you conditions for the business rule to make sure this is running on update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2019 12:21 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2019 12:57 AM
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;
}
- 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!