How to return a field value from script include?

Community Alums
Not applicable

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?

1 ACCEPTED SOLUTION

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: find_real_file.png

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

Even doing translatedNewValue = gr.label.toString(); didn't work

Community Alums
Not applicable

Initialized with New in beginning itself, still it returned 'null'. 

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: find_real_file.png

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Community Alums
Not applicable

Thankyou, it worked now.

I replaced if(gr.hasNext()) with if(gr.next()) then it worked. Not sure what is the difference though.

 

 

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.