---
title: "Before/after subscribe scripts"
canonical: "https://docs.perspectium.com/space/gold/1253231/Before%2Fafter+subscribe+scripts"
format: markdown
---
> Macro (html-bobswift)


## **<span style="color: #000000">Before subscribe scripts</span>**

---

<span style="color: #000000">Before subscribe scripts</span><span style="color: #333333"> are created with server-side JavaScript and will execute right before an insert or update allowing a chance to modify the record before persisting. Within your before subscribe script, you have access to the following variables:</span>


| **Variable** | **Description** |
| --- | --- |
| **current** | Record that is being inserted or updated |
| **repl_gr** | Temporary inbound record. Will be mapped to **repl_gr** by default. |
| **gr_before** | Record before any update is made to it. If the record doesn't exist (i.e., for an insert), then this variable will be assigned to current. |
| **qcurrent** | Record within the **psp_in_message** <span style="color: #000000">table (pulled from the </span>**Perspectium Mesh**<span style="color: #000000">).</span> <span style="color: #000000">Use the message's </span>**key**<span style="color: #000000"> value to determine its source.</span> |
| **ignore** | Can assign a value of **true** in order to stop the execution of the subscribe |
| **qcurrentxml** | Holds the xml object of the inbound record |
| **xml_util** | Holds an xml utility for working with **qcurrentxml** |


<span style="color: #000000">**After subscribe scripts**</span>

---

<span style="color: #000000">**After subscribe scripts**</span><span style="color: #000000"> are also created with server-side JavaScript and will run after an inbound (subscribed) record from a sharing instance is synced on the subscribing instance. Within your after subscribe script, you have access to the following variables:</span>

| <span style="color: #000000">**Variable**</span> | <span style="color: #000000">**Description**</span> |
| --- | --- |
| <span style="color: #000000">**current**</span> | <span style="color: #000000">Record that was inserted, updated or deleted, the destination record</span> |
| <span style="color: #000000">**qcurrent**</span> | <span style="color: #000000">Record within the </span>**<span style="color: #000000">psp_in_message</span>**<span style="color: #000000"> table (pulled from the </span>**<span style="color: #000000">Perspectium Mesh</span>**<span style="color: #000000">). Use the message's </span>**<span style="color: #000000">key</span>**<span style="color: #000000"> value to determine its source.</span> |
| <span style="color: #000000">**qcurrentxml**</span> | <span style="color: #000000">Holds the xml object of the inbound record</span> |
| <span style="color: #000000">**xml_util**</span> | <span style="color: #000000">Holds an xml utility for working with qcurrentxml</span> |
| <span style="color: #000000">**subscribe_gr**</span> | <span style="color: #000000">Holds the </span>[<span style="color: #000000">GlideRecord</span>](https://docs.servicenow.com/bundle/london-application-development/page/app-store/dev_portal/API_reference/glideRecordScoped/concept/c_GlideRecordScopedAPI.html)<span style="color: #000000"> object corresponding to the subscribe record configuration itself (You can use </span>**<span style="color: #000000">subscribe_gr.getTableName()</span>**<span style="color: #000000"> to access the name of the table you're trying to insert)</span> |

## **<span style="color: #000000">Prerequisites</span>**

---

:warning:<span style="color: #000000"> First, you will need to </span>[<span style="color: #000000">configure a ServiceNow instance as a subscriber</span>](https://docs-perspectium.atlassian.net/wiki/spaces/gold/pages/1297349)<span style="color: #000000">.</span>

## **<span style="color: #000000">Create before/after subscribe scripts</span>**

<span style="color: #000000">To create a before/after subscribe script, follow these steps:</span>

---

> Macro (ui-steps)
> 
> > Macro (legacy-content)
> 
> > Macro (legacy-content)
> 
> > Macro (legacy-content)
> 
> > Macro (legacy-content)
> 
> > Macro (legacy-content)



## **Similar topics**

---

> Macro (contentbylabel)

---

## **Contact Perspectium Support**

---

![image](media://16d69014-81c6-4309-a23b-839927a83f29)

#### <span style="color: #333333">**US: **</span>[<span style="color: #333333">**1 888 620 8880**</span>](tel:18886208880)

#### <span style="color: #333333">**UK: **</span>[<span style="color: #333333">**44 208 068 5953**</span>](tel:442080685953)

#### [<span style="color: #333333">**support@perspectium.com**</span>](mailto:support@perspectium.com)<span style="color: #333333">** **</span>** **