# Bonding to existing records

Sometimes there is a need to receive messages from an external system for records which exist in your system, but aren't bonded in Unifi.

To do this setup an inbound create message for the target integration, this will ensure that the bond is created. Add the code below to the top of your stage to target script, before any auto generated code. It will look up the existing record and repoint Unifi to use that record instead of creating a new one.

```javascript
var existing = new GlideRecord('change_request');
existing.addQuery(...); // Your look up code here - assuming other system knows ServiceNow sys_id/number
existing.query();

if (!existing.next()) {
  throw 'Target record with ID ' + /*whatever you use for your id here*/ + ' not found.';
}

target.$model.setRecord(existing);
target = target.$model.getRecord();
bond.setTarget(target.$model);
bond.setValue('internal_reference', target.number);
transaction.$model.setTarget(target);

bond.shouldCommitTarget(false);
bond.commit();
bond.shouldCommitTarget(true);
```


---

# 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.sharelogic.com/unifi/4.2/troubleshooting/development/bonding-to-existing-records.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.
