Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Translate client sciprt's messages on UI page

ApurvaS
Tera Contributor

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;
    }

 

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@ApurvaS 

share the complete code

OR use GlideAjax and use script include to return the translated value and then use in client script

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

yashkamde
Mega Sage

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.

Can we use gs.getMessage in client script?

no in server script, for using in client script you will need to use glideajax and script include for returning the message..