# Replacement scripts

## Introduction

Having [chosen to configure script replacements for a virtual environment](https://doc.wearepatchworks.com/product-documentation/virtual-environments/implementing-virtual-environments/configuring-a-virtual-environment-version/configuring-virtual-environment-replacements/..#configuring-replacements-for-a-virtual-environment-version), a new replacement rule is displayed, ready for you to configure:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FjjZ4tGr7qMsvzSpW1gNz%2Freplace%20script%201.png?alt=media&#x26;token=b4474af1-8f32-4651-85e8-11052bd7da94" alt=""><figcaption></figcaption></figure>

Having defined the first rule, you can add more - you must create one replacement rule for every [script](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting) that you need to replace in every process flow that will run in this environment.&#x20;

## Defining replacement rules for a script

{% stepper %}
{% step %}
**Select the required ORIGINAL script**

Use the `original` dropdown list to select the first script in a 'master' process flow that must be replaced when this process flow runs in the given virtual environment - for example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FmVrs3sWmn0WQSqqgpRgz%2Freplace%20script%202.png?alt=media&#x26;token=b5a4ffae-013f-4a5a-ace3-6ae0661c0ac5" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
As you work through your replacement configuration, it's helpful to view related ['master' process flows](https://doc.wearepatchworks.com/product-documentation/virtual-environments/implementing-virtual-environments/creating-a-master-process-flow) in another browser tab. You can duplicate a Patchworks browser tab and navigate to a different page whenever needed.
{% endhint %}
{% endstep %}

{% step %}
**Select the required ORIGINAL script version**

Move down to the field below and choose which version of the selected script to apply - for example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FOZVwQ239YpVF9MtBVVvq%2Freplace%20script%202a.png?alt=media&#x26;token=0a39df9e-1881-4fe8-aa8e-c8e97d52eced" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Select the required REPLACEMENT script**

Use the `replacement` dropdown list to select the replacement script that must be used when this process flow runs in the given virtual environment - for example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F674S4e0Kqw3pPbSduEQ7%2Freplace%20script%204.png?alt=media&#x26;token=1f968095-2404-46f0-b83f-95ac23fe693f" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Select the required REPLACEMENT script version**

Move down to the field below and choose which version of the selected script to apply - for example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FWQ2mrhtEu8vuyGCnp6Zq%2Freplace%20script%205a.png?alt=media&#x26;token=84a26e28-a3da-4b39-af15-c81acf8c41f1" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Confirm your selections**

Click the `create` button (associated with this replacement rule) to confirm your selections:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FGyTVKcO3PXMqWLky3a3h%2Freplace%20script%206.png?alt=media&#x26;token=0bb0cc98-e571-4b18-870c-44acfc013d0f" alt=""><figcaption></figcaption></figure>

The rule is added:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FNTeW4OfXNxQquqGQIJRL%2Freplace%20script%207.png?alt=media&#x26;token=fba90048-2bf8-4202-a3f6-97e402aaef64" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Once a rule is confirmed, it can't be edited. If you need to change a replacement rule, use the 'trash' icon to remove it and add a new one.
{% endhint %}
{% endstep %}

{% step %}
**Add more replacement rules for scripts**

To add another replacement rule for a script, click the top-right `create` button:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FpZi3Wre2Wo6JL96dPysq%2Freplace%20script%208.png?alt=media&#x26;token=f1dc9f14-85fd-41b9-8355-75b7f9e1a10c" alt=""><figcaption></figcaption></figure>

Update the new rule as required, then click the associated `create` button to confirm your selections:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FUkaCusOpZhPsUgFSBV3d%2Freplace%20script%209.png?alt=media&#x26;token=564febd1-b05a-4e11-af57-47200a6922dd" alt=""><figcaption></figcaption></figure>

Repeat as many times as needed to define all required script replacements for all process flows that will be running in this virtual environment.

{% hint style="info" %}
If you don't want to define ALL script lookup replacements now, that's OK. For example, you might choose to add the minimum number of replacements needed for [testing](https://doc.wearepatchworks.com/product-documentation/virtual-environments/implementing-virtual-environments/testing-a-process-flow-against-a-virtual-environment), then define remaining rules (in a [new draft](https://doc.wearepatchworks.com/product-documentation/virtual-environments/implementing-virtual-environments/configuring-a-virtual-environment-version/understanding-virtual-environment-versions)) later, after initial testing is complete.
{% endhint %}
{% endstep %}
{% endstepper %}
