Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

UI Messages translation on client script

Michele22
Tera Contributor

Hi all,

I see that is possible handle U Message translation also in client scripts.

If on server side I use the command

gs.getMessage('MY KEY');

I can use the ${} notation both on HTML and client script

HTML

<h1>${'MY KEY'}</h1>

Client Script

var message = ${'MY KEY'};

But my question is, how right handle on client side the messages key that contains parameters?

On server side I can use this notation:

gs.getMessage('Hi {0}, {1}', ['Mark', 'Good afternoon'] );

There is something similar on client side? 

Which is the best approach for this kind of sentences on client side?

I need to handle them inside a service portal widget.

Thanks

5 REPLIES 5

Shane41
ServiceNow Employee

Hi Michele,

You may find this previous thread helpful:

https://community.servicenow.com/community?id=community_question&sys_id=fbb3c3a5dbd8dbc01dcaf3231f96...

Hope this helps,

Shane

Hi Shane, thank you for your suggestions, but under Service Portal client script seems that getMessage() method doesn't work anyway.
For that reason I saw that on client script we can use the ${} API to get message content.
But I didn't find if there are a way to make also the parameters substitution.

Aman Kumar S
Kilo Patron

Hey,

One thing that I want to point, on client side, it works as :

getMessage("YOUR_MESSAGE_KEY", function(msgString) {
                g_form.showFieldMsg('field_name', msgString, 'error');
            });

 

getMessage(String) on client side uses only one parameter unlike server side.

Best Regards
Aman Kumar

Hi @Aman Kumar, thank you for your advice, but under Service Portal client script seems that getMessage() method doesn't work anyway.
For that reason I saw that on client script we can use the ${} API to get message content.
But I didn't find if there are a way to make also the parameters substitution.