Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

Read script helper functions for LFDocumentContentBuilder

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)

Use this function as a constructor for LFDocumentContentBuilder and includes the following parameters:

NameTypeDescription
VersionStringThe version type of the document content to be generated. For Australia, this value is v1.
targetLanguageStringThe 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\_idStringThe sys\_id of the artifact record.
tableNameStringThe table name of the artifact record.

processString (string, groupName, label)

Use this function to add the LFDocumentContentElement in the document content for the given string and includes the following parameters.

NameTypeDescription
stringStringThe value for which a document content entry is created.
groupNameStringThe name of the group to which element should belong.
labelStringThe unique label identifier for the created element.

processStringArray (stringArray, groupName, label)

Use this function to add elements (object of LFDocumentContentElement) in the document content for the given strings and includes the following parameters.

NameTypeDescription
stringArrayList of StringsThe list of values for which document content entry is created.
groupNameStringThe name of the group these strings belongs to.
labelStringThe unique label identifier for these strings.

processScript (scriptContent, groupName, label)

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:

NameTypeDescription
scriptContentStringThe Script to be processed to get the strings present as input of getMessage, gs.getMessage, or gs.getMessageLang.
groupNameStringThe name of the group for this input.
labelStringThe unique label identifier for this input.

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)

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:

NameTypeDescription
glideRecordGlideRecordThe GlideRecord object to be processed for translatable fields. The GlideRecord should be pointing to the valid table record.
groupNameStringThe name of the group for this input.

processTranslatableFieldsForMultipleRecords (tableName, encodedQuery, groupName)

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:

NameTypeDescription
tableNameStringThe table to fetch records.
encodedQueryStringThe encoded query for filtering records from the processTranslatableFieldsForSingleRecord table.
groupNameStringThe name of the group for this input.

processElement()

Use this function to add an element (object of LFDocumentContentElement) to LFDocumentContent object.

   
elementLFDocumentContentElementElement to be added to the document content.

build()

Returns the LFDocumentContent object.

Note: The getFinalJSON function has been deprecated in the Australia 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

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
        }
    }
}

Parent Topic:Artifact configurations