---
sourceDocument: Yokohama ServiceNow AI Platform Administration
sourceDocumentLink: https://www.servicenow.com/docs/r/yokohama/platform-administration

 Release :

    - yokohama

ft:locale :

    - en-US

ft:publication_title :

    - Yokohama ServiceNow AI Platform Administration

ft:clusterId :

    - platadm

bundleId :

    - platadm

workflow :

    - Platform


---

# Read script helper functions for LFDocumentContentBuilder

# Read script helper functions for LFDocumentContentBuilder {#ariaid-title1}

* Release version: Yokohama
* 
* Updated January 30, 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Read Script Helper Functions for LFDocumentContentBuilder

The LFDocumentContentBuilder is a utility in ServiceNow Yokohama release designed to facilitate the extraction and management of translatable content from various artifacts.
It supports localization tasks by enabling you to build document content objects that encapsulate translatable strings efficiently, regardless of whether standard translation tables are used.
Show full answer Show less  

## Key Functions and Their Uses

* **initialize(version, targetLanguage, sysid, tableName):** Acts as a constructor for LFDocumentContentBuilder, setting up the document version, target language, artifact record ID, and table name.
* **processString(string, groupName, label):** Adds a single translatable string to the document content under a specified group and label.
* **processStringArray(stringArray, groupName, label):** Adds multiple strings as document content elements, grouped and labeled appropriately.
* **processScript(scriptContent, groupName, label):** Parses provided script content to extract strings used in getMessage, gs.getMessage, or gs.getMessageLang calls and adds them to the document content.
* **processTranslatableFieldsForSingleRecord(glideRecord, groupName):** Extracts and adds all translatable fields (translatedfield, translatedtext, translatedhtml) from a single GlideRecord to the document content.
* **processTranslatableFieldsForMultipleRecords(tableName, encodedQuery, groupName):** Retrieves multiple records based on a table name and query, then adds their translatable fields to the document content.
* **processElement(element):** Directly adds a constructed LFDocumentContentElement to the document content object.
* **build():** Finalizes and returns the LFDocumentContent object; recommended over the deprecated getFinalJSON method.

## Practical Application

These functions enable ServiceNow customers to programmatically collect and organize all translatable content from records and scripts, making it easier to manage localization workflows. For example, you can create a document content object from a single record's translatable fields, add custom strings or script messages, and then build the content object for translation processing.

Once translation is complete, you can iterate through the LFDocumentContent elements and their fields to retrieve original and translated values, allowing you to update your records or artifacts accordingly.

## Example Usage

* Create a builder instance: `new LFDocumentContentBuilder("v1", language, sysId, tableName)`
* Extract translatable fields from a GlideRecord: `processTranslatableFieldsForSingleRecord(gr, "Basic Info")`
* Add custom elements and fields using helper functions, then add them via `processElement()`
* Generate the final document content object with `build()`
* After translation, access and process translated content by iterating over elements and fields from the LFDocumentContent object

## Why This Matters

By leveraging LFDocumentContentBuilder, you gain a standardized, scriptable way to extract, group, and manage translatable content across diverse ServiceNow artifacts. This streamlines localization tasks, ensuring that all relevant strings are captured for translation and properly reintegrated afterward, improving translation accuracy and efficiency.  
The LFDocumentContentBuilder provides utility functions to build
document content. Use these functions to write the logic to extract the translatable content
from any artifacts regardless of them using standard tables or not for translations.

## initialize (version, targetLanguage, sys_id, tableName) {#lf-document-content-builder__section_vf3_lqv_xnb}

Use this function as a constructor for LFDocumentContentBuilder and includes the following parameters:{#lf-document-content-builder__table_okx_rqv_xnb__entry__3}

| Name | Type | Description |
|-|-|-|
| Version | String | The version type of the document content to be generated. For Yokohama, this value is v1. |
| targetLanguage | String | The target language of the localization task document content. The target language is the same as the language available from the read script function argument. |
| Sys_id | String | The sys_id of the artifact record. |
| tableName | String | The table name of the artifact record. |
[ ]

{#lf-document-content-builder__table_okx_rqv_xnb}

## processString (string, groupName, label) {#lf-document-content-builder__section_xxg_3rv_xnb}

Use this function to add the LFDocumentContentElement in the document content for the given string and includes the following parameters.{#lf-document-content-builder__table_tfz_mrv_xnb__entry__3}

| Name | Type | Description |
|-|-|-|
| string | String | The value for which a document content entry is created. |
| groupName | String | The name of the group to which element should belong. |
| label | String | The unique label identifier for the created element. |
[ ]

{#lf-document-content-builder__table_tfz_mrv_xnb}

## processStringArray (stringArray, groupName, label) {#lf-document-content-builder__section_vwx_q5v_xnb}

Use this function to add elements (object of LFDocumentContentElement) in the document content for the given strings and includes the following parameters.{#lf-document-content-builder__table_o11_hvv_xnb__entry__3}

| Name | Type | Description |
|-|-|-|
| stringArray | List of Strings | The list of values for which document content entry is created. |
| groupName | String | The name of the group these strings belongs to. |
| label | String | The unique label identifier for these strings. |
[ ]

{#lf-document-content-builder__table_o11_hvv_xnb}

## processScript (scriptContent, groupName, label) {#lf-document-content-builder__section_xxt_wvv_xnb}

Use this function to add an element in the document content for the strings present as input of getMessage, gs.getMessage, or gs.getMessageLang in the provided Script. It has the following parameters:{#lf-document-content-builder__table_c4q_1wv_xnb__entry__3}

| Name | Type | Description |
|-|-|-|
| scriptContent | String | The Script to be processed to get the strings present as input of getMessage, gs.getMessage, or gs.getMessageLang. |
| groupName | String | The name of the group for this input. |
| label | String | The unique label identifier for this input. |
[ ]

{#lf-document-content-builder__table_c4q_1wv_xnb}  
For example,

    `var documentContentBuilder = new LFDocumentContentBuilder("v1", language, sysId, tableName);`
    `Var name = "name";`
    `documentContentBuilder .processScript("gs.getMessage('Hello {0}, How are you', name)", "Script_Group", "Script_Label");`

## processTranslatableFieldsForSingleRecord (glideRecord, groupName) {#lf-document-content-builder__section_oqr_x3w_xnb}

Use this function to create elements for the given glideRecord object, in document content for all its translatable fields. These translatable fields can be of translated_field, translated_text or translated_html types. It includes the following parameters:{#lf-document-content-builder__table_ukt_4jw_xnb__entry__3}

| Name | Type | Description |
|-|-|-|
| glideRecord | GlideRecord | The GlideRecord object to be processed for translatable fields. The GlideRecord should be pointing to the valid table record. |
| groupName | String | The name of the group for this input. |
[ ]

{#lf-document-content-builder__table_ukt_4jw_xnb}

## processTranslatableFieldsForMultipleRecords (tableName, encodedQuery,
groupName) {#lf-document-content-builder__section_rp5_rjw_xnb}

Use this function to fetch all the qualified records for the given tableName and encodedQuery and adds elements (object of LFDocumentContentElement) in the document content for all the translatable fields. It includes the following parameters:{#lf-document-content-builder__table_yg4_xjw_xnb__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | The table to fetch records. |
| encodedQuery | String | The encoded query for filtering records from the processTranslatableFieldsForSingleRecord table. |
| groupName | String | The name of the group for this input. |
[ ]

{#lf-document-content-builder__table_yg4_xjw_xnb}

## processElement() {#lf-document-content-builder__section_ps1_xh4_ypb}

Use this function to add an element (object of LFDocumentContentElement) to LFDocumentContent object.{#lf-document-content-builder__table_eny_mrb_zpb__entry__3}

|   |   |   |
|-|-|-|
| element | LFDocumentContentElement | Element to be added to the document content. |
[ ]

{#lf-document-content-builder__table_eny_mrb_zpb}

## build() {#lf-document-content-builder__section_okh_dkw_xnb}

Returns the LFDocumentContent object.  
Note:  
The getFinalJSON function has been deprecated in the Yokohama release and it is recommended to use the build() function.  
A sample script to build the document content.

    getTranslatableContent: function(params) {
        var tableName = params.tableName;
        var sysId = params.sysId;
        var language = params.language;
        var lfDocumentContentBuilder = new global.LFDocumentContentBuilder("v1", language, sysId, tableName);
        // This will create a new object of LFDocumentContent and stores it internally
        lfDocumentContentBuilder.processTranslatableFieldsForSingleRecord(gr, "Basic Info");
        var field = LFDocumentContentHelper.createField(originalValue, translatedValue);
        field.setTextType(LFDocumentContentHelper.PLAIN_TEXT_TYPE);
        // All the other relevant attributes can be set
        var element = LFDocumentContentHelper.createElement(groupName, label);
        element.addField(field);
        lfDocumentContentBuilder.processElement(element); // Adds element to the LFDocumentContent object
        return lfDocumentContentBuilder.build(); // return the LFDocumentContent object
    }

## Sample script to extract data from the LFDocumentContent {#lf-document-content-builder__section_n5g_rnb_zpb}

    saveTranslatedContent: function(documentContent) {
        // LFDocumentContent object is passed as an argument to the saveTranslatedContent 
        var targetLanguage = documentContent.getLanguage();
        var version = documentContent.getVersion();
        var elements = documentContent.getElements(); // Array of LFDocumentContentElement objects
        for (var idx = 0; idx < elements.length; idx++) {
            var element = elements[idx];
            var groupName = element.getGroupName();
            var fields = element.getFields(); // Array of LFDocumentContentField objects
            for (var fieldIdx = 0; fieldIdx < fields.length; fieldIdx++) {
                var field = fields[fieldIdx];
                var originalValue = field.getOriginalValue();
                var translatedValue = field.getTranslatedValue();
                // Get all the other required members and process them appropriately
            }
        }
    }


