---
title: "ServiceNow subscribe"
canonical: "https://docs.perspectium.com/space/Krypton/721367/ServiceNow%20subscribe"
format: markdown
---
The Perspectium application involves the transfer of data from a sharing instance flowing into a subscribing instance via the Integration Mesh. For this to happen, you need to set up both a shared queue on your sharing instance and a subscribing queue on your subscribing instance.  If you haven't set up these queues yet, please find more information and instructions to do so  here . Once you have set up these shared and subscribed queues, and have configured  how your data will be shared from your sharing instance , you must also configure how your subscribing instance will consume the shared data. This is done in the  Subscribe  module through the use of scripts.  Here are the ways in which you can use the  Subscribe  module to configure your ServiceNow subscribe instance.  Global  subscribe is a   Subscribe   definition that when created, will allow all incoming messages to be subscribed. If there is an existing subscribe definition for a specific table, its definition will override the global definition. About before and after subscribe scripts Once you have  configured a ServiceNow instance as a subscriber , you can use before/after subscribe scripts to customize how the data will be consumed and stored in your subscribing ServiceNow instance.  Before subscribe scripts These scripts are created with server-side JavaScript and will execute right  before  a record insert or update, allowing the chance to modify the record before persisting. Within your before subscribe script, you have access to the following variables: 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   table (pulled from the   Perspectium Mesh ).   Use the message's  key  value to determine its source. 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 ↑ Go to top of page After subscribe scripts These scripts are also created with server-side JavaScript and will execute right  after  a record from a sharing instance is synced on the subscribing instance. Within your after subscribe script, you have access to the following variables: Variable Description current Record that was inserted, updated or deleted, the destination record qcurrent Record within the   psp_in_message   table (pulled from the   Perspectium Mesh ). Use the message's  key  value to determine its source. qcurrentxml Holds the xml object of the inbound record xml_util Holds an xml utility for working with qcurrentxml subscribe_gr Holds the   GlideRecord   object corresponding to the subscribe record configuration itself (You can use   subscribe_gr.getTableName()   to access the name of the table you're trying to insert) ↑ Go to top of page Create before and after subscribe scripts Here's how to create these scripts: Log into your  sharing  ServiceNow instance that is sharing to the subscribing instance you want to configure, and go to  Perspectium   >   DataSync   >   Subscribe . In the resulting page, find and select the subscribe record that you want to configure. In the resulting subscribe record, click the  Filter and Enrichment  tab. You should see the  Before  subscribe script  and  After subscribe script  fields. Use the available fields to enter your desired scripts. See below for some examples. Once you're done, click  Update .  ↑ Go to top of page Examples of before and after subscribe scripts Below are some examples of scripts you can use to achieve specific results: ↑ Go to top of page Sync all source fields This feature is useful in cases when your sharing application has custom fields that do not typically exist in ServiceNow table schemas. Enabling the feature  will ensure that any custom or outlying fields in your source instance are properly synced in your subscribing instance by inserting missing fields. NOTES: If you use this  option, the fields that exist in your source instance and not in your subscribing instance will be created in your subscribing instance  with the initial letter of the field label capitalized only . For example, if you have a field in your sharing instance labeled custom FIELD, that field will be labeled in your target instance as  Custom field . The   Sync all source fields   option will not work if multiple subscribes are created for the same table and one subscribe has the   Skip incoming records with field discrepancies   option checked. Here's how to sync all source fields with the fields in your subscribing ServiceNow instance: Log into your  subscribing  ServiceNow instance and go to  Perspectium   >   DataSync   >   Subscribe . In the resulting page, find and select the subscribe record that you want to sync all source fields for. In the resulting subscribe record, click the  Source Instance  tab. Check the  Sync all source fields  box. This will reveal some new fields. Type the name of your sharing instance (e.g.,   dev12345 ) in the   Source Instance   field, and   username   and   password  of your sharing instance  in the appropriate fields. Click  Update .  ↑ Go to top of page