Formatting concatenated when generating a word document using ServiceNow Legal Contracts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 10:59 AM
When generating a word document from a contract template utilizing the ServiceNow Legal Contracts product, I have text that has line breaks in it that maps to fields in the contract. When the contract is generated, the line breaks are removed and all text gets concatenated. The flow is calling the WordDocumentAPI:
var generatedDocId = new sn_word_doc_api.WordDocumentAPI().generatePreviewDocument(inputs.document_id, {} ,inputs.field_mappings, inputs.target_table, inputs.target_sys_id, inputs.output_file_name).generatedAttachmentId;​
When looking at the flow action 'Generate Document', it is pulling all the field mappings in to a JSON that has the mapping in JSON escaped format with the individual '\n' instances still in tact. But, something is happening in the actual generation that ignores those '\n' instanes and concatenates the text as a string.
An example of what is happening:
Mapping (stored in a variable or a field on a table):
Objectives and Scope:
1. Objective 1
2. Objective 2
3. Objective 3
What shows up on the contract:
Objectives and Scope:1. Objective 12. Objective 23. Objective 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2023 09:19 AM
Hi @jslater1 ,
Here are a few steps you can take to troubleshoot and potentially resolve the issue:
-
Ensure Correct JSON Format:
- Verify that the JSON representation of the field mappings is correctly formatted. If there are any issues with escaping or special characters, it might affect how line breaks are interpreted.
-
Explicitly Add Line Breaks:
- Instead of relying on line breaks in the source data, you can try explicitly adding line breaks within the content where you want them in your Word document. Use the appropriate method based on the WordDocumentAPI requirements.
-
HTML Line Breaks:
- If your Word document supports HTML, you can try using HTML line breaks (
<br>
) in the source text. WordDocumentAPI might interpret HTML tags.
- If your Word document supports HTML, you can try using HTML line breaks (
-
Debugging:
- Introduce logging or debugging statements in your script to inspect the content at different stages of processing. This can help you identify where the issue might be occurring.
Here's an example of how you might modify your content to include explicit line breaks:
var contentWithLineBreaks = "Objectives and Scope:\n1. Objective 1\n2. Objective 2\n3. Objective 3";
// Include the modified content in your field mappings
var fieldMappings = {
// other mappings...
"objectives_and_scope": contentWithLineBreaks,
// other mappings...
};
// Call WordDocumentAPI with the modified field mappings
var generatedDocId = new sn_word_doc_api.WordDocumentAPI().generatePreviewDocument(
inputs.document_id,
{},
fieldMappings,
inputs.target_table,
inputs.target_sys_id,
inputs.output_file_name
).generatedAttachmentId;
Thanks,
Ratnakar