
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 01:25 AM
Hi all,
We've created document block content that is dynamically displayed based on the Subject person's language.
Unfortunately, when the document is previewed or generated, the HTML variable choice values are translated based on the current HR agent working on the case, not based on the Subject person's language (see the screenshot below).
Is there any way to specify which language to use in the HTML block or for specific variables? Or do you have any solution?
Thank you in advance,
Victoria
Solved! Go to Solution.
- Labels:
-
Human Resources Service Delivery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 01:47 AM
@Community Alums You need to use getDisplayValueLang(String language) method to fetch the translated text for the subject person.
Here are the details related to this method https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/no-namespace/c_GlideElementScopedAPI#SGE-getDisplayValueLang_S?navFilter=getDisplayValueLang
Here is an example code.
(function runTemplateScript(target /*GlideRecord for target task*/, docTemplate /*GlideRecord for doc template*/) {
//Add your code here to return the dynamic content for template
var getHeaderCell = function(label) {
return '<th style="border: 1px solid #dddddd; text-align: left; padding: 8px;">' + label + '</th>';
};
var getDataCell = function(value) {
return '<td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">' + value + '</td>';
};
var html = '';
var templateLang = docTemplate.getValue('language');
var templateDateFormat = docTemplate.getValue('template_date_format');
var hrTaskGr = new GlideRecord('sn_hr_core_contact');
hrTaskGr.addQuery('user', target.getValue('subject_person'));
hrTaskGr.query();
while(hrTaskGr.next()) {
var dob = hrTaskGr.getDisplayValue('date_of_birth');
var grDOB = new GlideDateTime(dob);
html = html + '<tr>';
html = html + getDataCell(hrTaskGr.getDisplayValue('name'));
html = html + getDataCell(hrTaskGr.getDisplayValue('mobile_phone'));
html = html + getDataCell(hrTaskGr.getElement('relation_to_employee').getDisplayValueLang(templateLang));
html = html + getDataCell(hrTaskGr.getElement('priority').getDisplayValueLang(templateLang));
html = html + getDataCell(grDOB.getLocalDate().getByFormat(templateDateFormat)
);
html = html + '</tr>';
}
if(!gs.nil(html))
html = '<h4>Emergency Contact Information</h4><table width="500px;"><tr>' + getHeaderCell('Name') + getHeaderCell('Mobile phone') + getHeaderCell('Relationship') + getHeaderCell('Priority') + getHeaderCell('Date of birth') + html + '</table>';
return html;
})(target, docTemplate);
Source: Here is the reference from where this code was copied https://docs.servicenow.com/bundle/washingtondc-employee-service-management/page/product/human-resources/concept/document-template-scripts.html
In your case, you need to fetch the language of the subject person and use it as follows.
hrTaskGr.getElement('priority').getDisplayValueLang(taget.subject_person.preferred_language);
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 01:47 AM
@Community Alums You need to use getDisplayValueLang(String language) method to fetch the translated text for the subject person.
Here are the details related to this method https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/no-namespace/c_GlideElementScopedAPI#SGE-getDisplayValueLang_S?navFilter=getDisplayValueLang
Here is an example code.
(function runTemplateScript(target /*GlideRecord for target task*/, docTemplate /*GlideRecord for doc template*/) {
//Add your code here to return the dynamic content for template
var getHeaderCell = function(label) {
return '<th style="border: 1px solid #dddddd; text-align: left; padding: 8px;">' + label + '</th>';
};
var getDataCell = function(value) {
return '<td style="border: 1px solid #dddddd; text-align: left; padding: 8px;">' + value + '</td>';
};
var html = '';
var templateLang = docTemplate.getValue('language');
var templateDateFormat = docTemplate.getValue('template_date_format');
var hrTaskGr = new GlideRecord('sn_hr_core_contact');
hrTaskGr.addQuery('user', target.getValue('subject_person'));
hrTaskGr.query();
while(hrTaskGr.next()) {
var dob = hrTaskGr.getDisplayValue('date_of_birth');
var grDOB = new GlideDateTime(dob);
html = html + '<tr>';
html = html + getDataCell(hrTaskGr.getDisplayValue('name'));
html = html + getDataCell(hrTaskGr.getDisplayValue('mobile_phone'));
html = html + getDataCell(hrTaskGr.getElement('relation_to_employee').getDisplayValueLang(templateLang));
html = html + getDataCell(hrTaskGr.getElement('priority').getDisplayValueLang(templateLang));
html = html + getDataCell(grDOB.getLocalDate().getByFormat(templateDateFormat)
);
html = html + '</tr>';
}
if(!gs.nil(html))
html = '<h4>Emergency Contact Information</h4><table width="500px;"><tr>' + getHeaderCell('Name') + getHeaderCell('Mobile phone') + getHeaderCell('Relationship') + getHeaderCell('Priority') + getHeaderCell('Date of birth') + html + '</table>';
return html;
})(target, docTemplate);
Source: Here is the reference from where this code was copied https://docs.servicenow.com/bundle/washingtondc-employee-service-management/page/product/human-resources/concept/document-template-scripts.html
In your case, you need to fetch the language of the subject person and use it as follows.
hrTaskGr.getElement('priority').getDisplayValueLang(taget.subject_person.preferred_language);
Hope this helps.