{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":38997,"path":"platform-administration/localization-framework/lf-document-content-builder.md","title":"Read script helper functions for LFDocumentContentBuilder","bundle":null,"doc_type":null,"release":"australia","body":"\n# Read script helper functions for LFDocumentContentBuilder\n\nThe 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.\n\n## initialize \\(version, targetLanguage, sys\\_id, tableName\\)\n\nUse this function as a constructor for LFDocumentContentBuilder and includes the following parameters:\n\n<table id=\"table_okx_rqv_xnb\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nVersion\n\n</td><td>\n\nString\n\n</td><td>\n\nThe version type of the document content to be generated. For Australia, this value is v1.\n\n</td></tr><tr><td>\n\ntargetLanguage\n\n</td><td>\n\nString\n\n</td><td>\n\nThe target language of the localization task document content. The target language is the same as the language available from the read script function argument.\n\n</td></tr><tr><td>\n\nSys\\_id\n\n</td><td>\n\nString\n\n</td><td>\n\nThe sys\\_id of the artifact record.\n\n</td></tr><tr><td>\n\ntableName\n\n</td><td>\n\nString\n\n</td><td>\n\nThe table name of the artifact record.\n\n</td></tr></tbody>\n</table>## processString \\(string, groupName, label\\)\n\nUse this function to add the LFDocumentContentElement in the document content for the given string and includes the following parameters.\n\n|Name|Type|Description|\n|----|----|-----------|\n|string|String|The value for which a document content entry is created.|\n|groupName|String|The name of the group to which element should belong.|\n|label|String|The unique label identifier for the created element.|\n\n## processStringArray \\(stringArray, groupName, label\\)\n\nUse this function to add elements \\(object of LFDocumentContentElement\\) in the document content for the given strings and includes the following parameters.\n\n|Name|Type|Description|\n|----|----|-----------|\n|stringArray|List of Strings|The list of values for which document content entry is created.|\n|groupName|String|The name of the group these strings belongs to.|\n|label|String|The unique label identifier for these strings.|\n\n## processScript \\(scriptContent, groupName, label\\)\n\nUse 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:\n\n|Name|Type|Description|\n|----|----|-----------|\n|scriptContent|String|The Script to be processed to get the strings present as input of getMessage, gs.getMessage, or gs.getMessageLang.|\n|groupName|String|The name of the group for this input.|\n|label|String|The unique label identifier for this input.|\n\nFor example,\n\n```\n`var documentContentBuilder = new LFDocumentContentBuilder(\"v1\", language, sysId, tableName);`\n`Var name = \"name\";`\n`documentContentBuilder .processScript(\"gs.getMessage('Hello {0}, How are you', name)\", \"Script_Group\", \"Script_Label\");`\n```\n\n## processTranslatableFieldsForSingleRecord \\(glideRecord, groupName\\)\n\nUse 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:\n\n|Name|Type|Description|\n|----|----|-----------|\n|glideRecord|GlideRecord|The GlideRecord object to be processed for translatable fields. The GlideRecord should be pointing to the valid table record.|\n|groupName|String|The name of the group for this input.|\n\n## processTranslatableFieldsForMultipleRecords \\(tableName, encodedQuery, groupName\\)\n\nUse 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:\n\n|Name|Type|Description|\n|----|----|-----------|\n|tableName|String|The table to fetch records.|\n|encodedQuery|String|The encoded query for filtering records from the processTranslatableFieldsForSingleRecord table.|\n|groupName|String|The name of the group for this input.|\n\n## processElement\\(\\)\n\nUse this function to add an element \\(object of LFDocumentContentElement\\) to LFDocumentContent object.\n\n| | | |\n|---|---|---|\n|element|LFDocumentContentElement|Element to be added to the document content.|\n\n## build\\(\\)\n\nReturns the LFDocumentContent object.\n\n**Note:** The getFinalJSON function has been deprecated in the Australia release and it is recommended to use the build\\(\\) function.\n\nA sample script to build the document content.\n\n```\ngetTranslatableContent: function(params) {\n    var tableName = params.tableName;\n    var sysId = params.sysId;\n    var language = params.language;\n    var lfDocumentContentBuilder = new global.LFDocumentContentBuilder(\"v1\", language, sysId, tableName);\n    // This will create a new object of LFDocumentContent and stores it internally\n    lfDocumentContentBuilder.processTranslatableFieldsForSingleRecord(gr, \"Basic Info\");\n    var field = LFDocumentContentHelper.createField(originalValue, translatedValue);\n    field.setTextType(LFDocumentContentHelper.PLAIN_TEXT_TYPE);\n    // All the other relevant attributes can be set\n    var element = LFDocumentContentHelper.createElement(groupName, label);\n    element.addField(field);\n    lfDocumentContentBuilder.processElement(element); // Adds element to the LFDocumentContent object\n    return lfDocumentContentBuilder.build(); // return the LFDocumentContent object\n}\n\n```\n\n## Sample script to extract data from the LFDocumentContent\n\n```\nsaveTranslatedContent: function(documentContent) {\n    // LFDocumentContent object is passed as an argument to the saveTranslatedContent \n    var targetLanguage = documentContent.getLanguage();\n    var version = documentContent.getVersion();\n    var elements = documentContent.getElements(); // Array of LFDocumentContentElement objects\n    for (var idx = 0; idx < elements.length; idx++) {\n        var element = elements[idx];\n        var groupName = element.getGroupName();\n        var fields = element.getFields(); // Array of LFDocumentContentField objects\n        for (var fieldIdx = 0; fieldIdx < fields.length; fieldIdx++) {\n            var field = fields[fieldIdx];\n            var originalValue = field.getOriginalValue();\n            var translatedValue = field.getTranslatedValue();\n            // Get all the other required members and process them appropriately\n        }\n    }\n}\n```\n\n**Parent Topic:**[Artifact configurations](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/platform-administration/localization-framework/framework-configuration.md)\n\n"}}