Translate client sciprt's messages on UI page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Below is code we are using in a UI page client script for validations, how we can achieve translation for this error messages?
if (additionalComment == "" && (todayDate > formatReturnDateValue) && choiceValue == "noneValue") {
error.textContent = "* field mandatory";
error.style.color = "red";
dateError.textContent = "Enter future date";
dateError.style.color = "red";
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
share the complete code
OR use GlideAjax and use script include to return the translated value and then use in client script
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hello @ApurvaS ,
I would recommend you to create pre defined messages:
navigate System UI > Messages :
> Key: field.mandatory, Message: * field mandatory
> Key: enter.future.date, Message: Enter future date
get this messages using server script :
var mandatoryMsg = gs.getMessage("field.mandatory");
var futureDateMsg = gs.getMessage("enter.future.date");
if (additionalComment == "" && (todayDate > formatReturnDateValue) && choiceValue == "noneValue") {
error.textContent = mandatoryMsg;
error.style.color = "red";
dateError.textContent = futureDateMsg;
dateError.style.color = "red";
return false;
}
Note : It is consider as best practice to keep all user facing text in message properties rather than hardcoding. This makes your application multilingual-ready and easier to maintain.
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
43m ago
Can we use gs.getMessage in client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
38m ago
no in server script, for using in client script you will need to use glideajax and script include for returning the message..
