**Source URL:** https://medical.veevavault.help/en/lr/39449/

# Configuring the Veeva CRM Data Agnostic Connector (MedInquiry)

Veeva CRM customers can enable the CRM Connection, which allows Vault to pull _Medical Inquiry_ records from CRM and close the inquiry in CRM when the case is closed in MedInquiry. Vault pulls _Medical Inquiry_ records in the _Submitted_ or _Saved_ states that are assigned to the _Medical Inquiry Integration User_ using a scheduled job to create corresponding _Case_ and _Case Request_ records. Then, Vault pushes the status of records in the _Closed_ state back to CRM using a second scheduled job. By default, Vault sends a status update to CRM indicating that the inquiry is closed.

This feature is separate from the CRM Data Sharing feature and does not require you to sync CRM Accounts to MedInquiry prior to pulling inquiries.

Vault notifies the user initiating the job or the job owner upon failure or completion of the job. You can schedule jobs to run the connection. You can also manually run the pull and push jobs by performing the actions on the integration points.

This feature must be enabled by Support. Once this feature is enabled, navigate to **Admin > Settings > Application Settings** and, under _Medical Inquiry_, select the **Sync CRM Inquiries with MedComms** checkbox.

This feature can only be enabled when the Medical Inquiry CRM Data Sharing feature is disabled.

To create the Connection, create a **CRM Org** object with the _Medical Inquiry integration_ selected. Vault provides the initial setup from the _CRM Org_ record. You must enter the **CRM Org Type** and **CRM Org ID** fields on applicable _CRM Org_ records. You must also enter a **CRM Username**.

You must configure the following components to use the CRM Connection:

  * Add the _Veeva ID_ and _OpenData Healthcare Provider ID_ fields to the _Case Contact_ object type on the _Person_ object.
  * Add the _Mobile_, _CRM Org_, _External ID_, and _Source_ fields to the _Associated Contact_ object type.
  * Update the _Email_ field on the _Associated Contact_ object type to be optional.
  * On the _Person_ object, clear the _Must Be Unique_ checkbox on the _External ID_ field.
  * Add the _Last CRM Data Share_ and _Source CRM Org_ fields to the _Case_ object page layout
  * Configure the user action and add your CRM Connection credentials.

### Authorizing the Connection

First, you must configure the action to authorize credentials:

  1. Navigate to **Admin > Configuration > Objects > Connection Authorization**.
  2. Click the **Actions** tab.
  3. Click **Create**.
  4. Select **Enter Salesforce Connected App Details** and click **Continue**.
  5. Optional: Enter a **Description**.
  6. Click **Save**.
  7. Navigate to the **Object Type** tab.
  8. Click the **Actions** menu.
  9. Select **Edit Object Type Actions**.
  10. Add the **Enter Salesforce Connected App Details** action to the **Basic Auth Object Type**.
  11. Click **Save**.

Next, add your credentials:

  1. Navigate to **Admin > Connections > Connection Authorizations**.
  2. Click the desired authorization or create a new **Connection Authorization**.
  3. Click **Edit**.
  4. Enter your Veeva CRM **User Name**, then click **Save**.
  5. Click the **Actions** menu and select **Set Password**.
  6. Enter your CRM password, then click **Save**.
  7. Click the **Actions** menu and select **Enter Salesforce Connected App Details**.
  8. Enter your **Client ID / Connected App Consumer Key** and **Secret / Connected App Consumer Secret**.
  9. Click **Save**.

### Configuring Integration Rules

After authorizing the CRM Connection, you must add and configure integration rules to suit your business logic. You can create a single set of inbound integration rules for the integration point. The outbound push job does not support integration rules, and only pushes a status update back to Veeva CRM to close the Medical Inquiry when the _Case_ is closed in Vault.

To configure integration rules:

  1. Navigate to **Admin > Connections > Integration Rules**.
  2. Click **Create**.
  3. Enter a **Label** and a **Name**.
  4. Select a **Connection**.
  5. Select an **Integration Point**.
  6. Click **Save**.

#### Field Rules

Next, you must add field rules for each field you want Vault to populate. Field rules should account for the fields you want to sync from the Medical Inquiry in CRM into Vault. You can specify default values for fields that are excluded from the transfer between applications using a record with only the target object and field populated alongside the type and default value. Vault also applies defaults if the CRM record has no value selected.

Vault limits the _Medical Inquiry_ transfer to the sources used and only pulls the fields for the given query object, the Medical Inquiry record in CRM.

**Note**: MedInquiry uses certain fields as a core part of the CRM connection. Do not add field rules to the following fields:

  *  `source__v`
  *  `status__v`
  *  `object_type__v`
  *  `closed_date__v`
  *  `response_contact__v`
  *  `case_contact__v`
  *  `veeva_id__sys`
  *  `external_id__v`
  *  `crm_mifr_external_id__v`
  *  `crm_org__v`
  *  `crm_data_share_date__v`
  *  `crm_last_modified_date__v`
  *  `source_crm_org__v`

| Field Rule Property | Descriptiom |
| --- | --- |
| Target Object | The object you are using in Vault.|
| Target Object Field | The object field in Vault for which you are creating the rule. |
| Label | The label identifying the field rule. |
| Name | The key identifying the field rule. |
| Field Default | The value to assign to the field if the field is blank. If you are using a referenced object such as _Product Family_, use the _ID_. |
| Reference Lookup Type | Supports mapping values in CRM to Vault and Vault to CRM. For example, CRM may return _Cholecap_ in the _Product Family_ field, which is stored as `cholecap__v` in Vault. |
| Reference Lookup | A link to a reference lookup for the matching type. Reference lookups contain a set of values and can be shared. For example, you can use a reference lookup for the _Product Family_ object in multiple field rules. |
| Query Object | The object in CRM to which this field rule relates. |
| Query Field | The field on the object in CRM to which this field relates. |
| Query Field Type | The field type to which this relates. This property is optional. |

### Create a Scheduled Pull Job

Next, you must configure the action to authorize credentials:

  1. Navigate to **Operations > Job Definitions** and click **Create Job**.
  2. Enter a **Title** and a **Name**.
  3. Under _Type_, select **SDK Job**.
  4. Under _Job_, select `com.veeva.vault.app.medical.medicalinquiry.crmorg.jobs.CRMOrgMedicalInquiryPullSchedulingJob (Medical Inquiry (CRM Connection Inquiry Pull))`.
  5. Define a schedule.
  6. Select a **Job Owner**.
  7. Select **Active** in the _Status_ drop-down.
  8. Click **Save**.

### Create a Scheduled Push Job

Then, you must configure a second action to authorize credentials:

  1. Navigate to **Operations > Job Definitions** and click **Create Job**.
  2. Enter a **Title** and a **Name**.
  3. Under _Type_, select **SDK Job**.
  4. Under _Job_, select `com.veeva.vault.app.medical.medicalinquiry.crmorg.jobs.push.CRMOrgMedicalInquiryPushJob (Medical Inquiry (Inquiry Push Job) - NA Commercial Org)`.
  5. Define a schedule.
  6. Select a **Job Owner**.
  7. Select **Active** in the _Status_ drop-down.
  8. Click **Save**.

### Create a Local Connection

The scheduled job requires a connection to allow Vault to read data from the _CRM Org_ and _Connection_ objects.

To create a new connection:

  1. Enter a **Name**.
  2. Enter **medcomms\_local** as the _API Name_.
  3. Under _Connection Type_, select **Local**.
  4. Enter a **Description**.
  5. Select an **Authorized Connection User**. This is the user with permission to to run the scheduled job.

Next, add an action to run the job:

  1. Navigate to **Configuration > Objects > Integration > Actions**.
  2. Select **Create**.
  3. Add the **Execute Medical Inquiry Pull** job.

**Important**: When the job first runs, the connection will obtain the CRM Org URL and will not pull any inquiries. While the job status may state `ERRORS ENCOUNTERED` and may include the message, `Destination URL not reset. The URL returned from login must be set`, subsequent jobs will be successful.

