---
title: "Optional features for dynamic shares and bulk shares"
canonical: "https://docs.perspectium.com/space/Lithium/2326806/Optional%20features%20for%20dynamic%20shares%20and%20bulk%20shares"
format: markdown
---
# Truncate Fields

> ℹ️ Available in **Lithium 9.7.0 and newer**

Because ServiceNow allows you to enter more text than you define as the field’s max length, this feature allows you to truncate the text to the max length of the field.

This is one way to avoid performance issues when the Perspectium application is trying to query for a record and it takes a long time to query and create the outbound message for sharing due to the abnormally large size of one field in the record.

To avoid having to truncate every single field of a record (which would take a long time to process), you specify the max length value you want to truncate in [DataSync Settings](https://docs-perspectium.atlassian.net/wiki/spaces/Lithium/pages/2327410). Any field that has a max length equal to or greater than this value will be truncated to the field’s maximum length with a Before Share Script. 

For example, if your table has two fields (description with a max length of 4000 and notes with a max length of 8000), and you specify the max length to truncate as 4000 in DataSync Settings, when you select the **Truncate Fields** option on your share, this will create a **Before Share Script** on the share with:

```
// START TRUNCATE FIELDS SCRIPT
if (String(current.notes).length > 8000) {
	current.notes = String(current.notes).substring(0, 8000);
}

if (String(current.description).length > 8000) {
	current.description = String(current.description).substring(0, 8000);
}
// END TRUNCATE FIELDS SCRIPT
```

![truncate_fields_before_share_script_example.png](media://d7b5c9b1-e2aa-4d0d-9f20-5a3e51dfc438)

Here’s how to enable this feature.  

1. Create a [bulk share](https://docs-perspectium.atlassian.net/wiki/spaces/Lithium/pages/2326799) or [dynamic share](https://docs-perspectium.atlassian.net/wiki/spaces/Lithium/pages/2326993).
2. Select the **Standard view **Related Links UI action at the bottom.
3. Go to the **Advanced** tab.
4. Go to the **Runtime Settings** section and select the **Truncate fields** option.
5. Save your share.

If you go back into your share now and go to the **Scripting** tab, you will see the added script to truncate fields that have a max length greater than or equal to the value specified in DataSync Settings. To distinguish the truncate fields script from any other script you have in the Before Share Script, the truncate fields script will be surrounded by the **// START TRUNCATE FIELDS SCRIPT** and **// END TRUNCATE FIELDS SCRIPT **comments.

> ℹ️ Notes:
> ℹ️ 
> ℹ️ - For bulk shares, like other bulk share configurations, you can only enable/disable the Truncate Fields option before it has executed.
> ℹ️ - \n, \t (for newlines and tabs) and other similar formatting characters are counted as characters when truncating since these characters are actually in the content. So you may not see exactly the same number of characters on screen as the max length truncated i.e. you may not see exactly 4000 on screen characters and instead may see slightly less to account for formatting characters. This is what the system retruns to us as 4000 characters when we request for a truncated version.
> ℹ️ - To prevent duplicate truncate field scripts and also account for changes in the sharing table’s fields and their definitions (such as a new field being added with a max length greater than the current setting), when you update a share with this option enabled, it will delete anything between the **// START TRUNCATE FIELDS SCRIPT** and **// END TRUNCATE FIELDS SCRIPT **comments to rebuild the truncate fields script. So any content you type in manually between these comments will also be deleted. Any scripts that is outside of these comments will be maintained in the Before Share Script.
> ℹ️ - When you toggle off the Truncate Fields option, it will delete the truncate field script currently in the Before Share Script, deleting any content between the **// START TRUNCATE FIELDS SCRIPT** and **// END TRUNCATE FIELDS SCRIPT **comments.


<u>[↑ Go to top of page](https://docs-perspectium.atlassian.net/wiki/spaces/Lithium/pages/2326806/Optional+features+for+dynamic+shares+and+bulk+shares#Topofpage)</u>