# Creating and Editing Scripts

{% embed url="<https://youtu.be/n8NpWWIjmlA>" %}
DocBits Document Scripts Explained: Automate Custom Logic in Your Document Workflow
{% endembed %}

## To create a new script in DocBits, follow these detailed instructions:

**Choose the scripting language:**

First, you need to choose the scripting language you want to use. DocBits typically supports common scripting languages ​​such as Python, JavaScript, or SQL. The choice of language depends on the needs of your project and your own competency.

**Open the script development environment:**

Log in to DocBits and navigate to the script development environment. This is in the administration area.

<figure><img src="/files/a3UmxZ1r6RF8MDbEDSLZ" alt="Script Development Environment Overview"><figcaption></figcaption></figure>

**Create a new script:**

Click the "+ New" button to open a new script editor.

<figure><img src="/files/yzJWs3nEofVQJgCEhEL8" alt="Create New Script Button"><figcaption></figcaption></figure>

**Write the code:**

Use the editor to write the code for your script. Start with the basic syntax of your chosen scripting language.

For example, if you are using Python, your script might look like this:

## 1. Example script in Python

<figure><img src="/files/DxMzejFKnVRej4eYKKv2" alt="Python Script Example 1"><figcaption></figcaption></figure>

## Function to clean patient names

def clean\_patient\_name(name): cleaned\_name = name.strip().title() # Remove spaces and apply capitalization

return cleaned\_name

## Main program

if **name** == "**main**": patient\_name = " john doe " cleaned\_name = clean\_patient\_name(patient\_name) print("Cleaned patient name:", cleaned\_name)

## 2. Example script

<figure><img src="/files/IUEoOLmJCCDx6GE9reeG" alt="Python Script Example 2"><figcaption></figcaption></figure>

**Test the script:**

Check the code for errors and test it in a test environment. Make sure the script produces the expected results and works correctly.

<figure><img src="/files/yBdAcdhJTwg4gVSQlVsp" alt="Script Testing Interface"><figcaption></figcaption></figure>

**Save the script:**

Save the script in DocBits and give it a meaningful name that describes the purpose of the script.

<figure><img src="/files/Ic8MHC5Jw6E9JzGPTf8Q" alt="Save Script Button" width="84"><figcaption></figcaption></figure>

**Mapping the script to document types:**

An important step is mapping the script to the appropriate document types. This determines when and how the script is applied. This can usually be done through a configuration interface in DocBits, where you can assign the script to a specific document type and specify under which conditions it should be applied.

<figure><img src="/files/SeRK1zsKtNH7VgXmPpiO" alt="Script Document Type Mapping"><figcaption></figcaption></figure>

**Review and publish:**

After you have created, tested and mapped the script, check it again for errors and inconsistencies. If everything is OK, you can publish the script to the DocBits production environment.

<figure><img src="/files/IvieS0LEpJ460HZlBpxH" alt="Script Review and Publish"><figcaption></figcaption></figure>

<figure><img src="/files/ydAR5ILDyScn9lUfcnZU" alt="Script Publish Confirmation"><figcaption></figcaption></figure>

Through these steps, you can successfully create, test and implement a new script in DocBits to automate processes and improve the efficiency of medical documentation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.docbits.com/administration-and-setup/settings/global-settings/document-types/script/creating-and-editing-scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
