- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 03:56 AM
Hi,
I am trying to get language of logged in User and based that I want translated value of a UI Action button. So as below script include should return "Neu" when language is "de".
Script Include:
var ButtonsForRelatedList = Class.create();
ButtonsForRelatedList.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getButtonsForRelatedList:function(){
var langOfUser = gs.getSession().getLanguage();
var translatedNewValue;
if(langOfUser != 'en'){
var gr = new GlideRecord('sys_translated');
gr.addQuery('name', 'sys_ui_action');
gr.addQuery('language', langOfUser);
gr.addQuery('value', 'New');
gr.query();
if(gr.hasNext()){
translatedNewValue = gr.label;
}
}
else{
translatedNewValue = "New";
}
return translatedNewValue;
},
type: 'ButtonsForRelatedList'
});
Client Script
function onLoad() {
var state = g_form.getValue('state');
if(state == '3' || state =='7'){//state is closed or cancelled
var ga = new GlideAjax('ButtonsForRelatedList');
ga.addParam('sysparm_name', 'getButtonsForRelatedList');
ga.getXML(getResponse);
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
So I am getting answer as null instead of 'Neu'.
Something is going wrong in translatedNewValue = gr.label; in script include. Even when I tried in background script, it is not giving me value. Suggest what I am doing wrong over here?
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 04:23 AM
this script worked for me in background script execution.
var gr = new GlideRecord("sys_translated");
gr.addEncodedQuery("name=sys_app_application^value=Call Center");
gr.query();
while(gr.next()){
gs.print(gr.getValue("label")+"\n");
}
output:
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 04:13 AM
Even doing translatedNewValue = gr.label.toString(); didn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 04:12 AM
Initialized with New in beginning itself, still it returned 'null'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 04:23 AM
this script worked for me in background script execution.
var gr = new GlideRecord("sys_translated");
gr.addEncodedQuery("name=sys_app_application^value=Call Center");
gr.query();
while(gr.next()){
gs.print(gr.getValue("label")+"\n");
}
output:
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 04:32 AM
Thankyou, it worked now.
I replaced if(gr.hasNext()) with if(gr.next()) then it worked. Not sure what is the difference though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2023 12:15 PM
Hi Sindhu,
I am also facing the same issues as yours. I tried all the ways which are discusssed above.
I will be very helpful, if you can share the code with me if possible.