- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 05:12 AM
Good evening
On a Catalog form, based on Country is Thailand, then it should allow the below 3 Address line Fields to only take 70 characters/digit length.
How can I do this? Please guide.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 04:42 AM
function onSubmit() {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 05:51 AM
I am not an expert in coding, but something
If Country = xx
Then
Value some things.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 08:13 AM
You can enforce this character limit restriction dynamically using Client Scripts:
using Client Scripts >> Go to the Catalog Client Scripts >> Click New
in there Type should be onChange and pass the Variable Name country (Make sure this matches your Country field variable name)
// Check if Country is Thailand
if (newValue === "Thailand") {
// Define Address Field values
var addressValues = ["address_line_1", "address_line_2", "address_line_3"];
addressValues.forEach(function(field) {
var addressField = g_form.getControl(field);
if (addressField) {
// Set Maximum Length to 70
addressField.maxLength = 70;
g_form.showFieldMsg(field, "Maximum 70 characters allowed for Thailand.", "info");
}
});
} else {
// Remove field restriction if not Thailand
var addressValues = ["address_line_1", "address_line_2", "address_line_3"];
addressValues.forEach(function(field) {
var addressField = g_form.getControl(field);
if (addressField) {
addressField.removeAttribute("maxLength");
g_form.clearMessages();
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 04:46 AM
Thanks a lot Harry. I just modified and got the code as below:
Correct Answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 04:42 AM
function onSubmit() {