Navbar

MyInsights

Getting Started

MyInsights allows customers to create custom visualizations using the Veeva JavaScript library and HTML. These visualizations can be directly delivered to users in the field via CRM, and display contextual and historical information to assist users in their day-to-day activities. Developers can assist in creating these visualizations leveraging real-time information from Veeva CRM. The content can be used to approve orders, review overall sales data, and view account plans.

Your company administrator must first set up MyInsights in their Veeva CRM Org. See MyInsights Configuration for more information.

Creating Visualizations

To start, you need to create an index.html file. This file contains the code your company administrator uploads into their Veeva CRM Org to generate your MyInsight visualization.

This is a sample of the code:


<!DOCTYPE HTML>

<html>
  <head>
    <title>Getting Started with MyInsights</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  </head>

  <body>
    <!-- Your printToScreen function -->
    <h2 id="test"> </h2>

    <p> Hello, world! This is my MyInsights visualization.</p>
  </body>

  <!-- your  javascript file goes here -->
  <script language="JavaScript" type="text/javascript" src="q.js"></script>
  <script language="JavaScript" type="text/javascript" src="MyInsightsLibrary.js"></script>
  <script language="JavaScript" type="text/javascript" src="main.js"></script> 
</html>

Querying for Veeva CRM Data

In order to query for CRM data, you need to use the following JavaScript libraries:

  1. MyInsights.js

    Use this library to call information from your Veeva CRM org. The MyInsights library can be found on the JS Libraries tab.

  2. Q.js

    Use this library to work with promises as returns when using the MyInsights library methods. The Q library can be found on Github.

  3. main.js

    This is a required custom file. It controls how content displays. Users can link to it in a controller file. For our example, we’ve linked to our custom file, named main.js. Alternatively, you can put your main.js file inline.

This is an example of how to reference the JavaScript libraries:

<script language="JavaScript" type="text/javascript" src="q.js"></script>
<script language="JavaScript" type="text/javascript" src="MyInsightsLibrary.js"></script>
<script language="JavaScript" type="text/javascript" src="main.js"></script> 

MyInsights Methods

There are several MyInsights methods you can use to create a visualization. See MyInsights methods for more information.

For this example, we are using the queryRecord method.

The queryRecord method can be used to look for the API fields of an account, for example, Phone, Name, and Fax.

Insert the following snippet in the main.js file:


  function start() {
    queryCRMData();
  }

  function queryCRMData() {
    var queryConfig = {
      object: "Account",
      fields: ["Name", "Phone", "sFax"],
      where: "",
      sort: [],
      limit: "10"
    };

    ds.queryRecord(queryConfig).then(
      function (resp) {
        console.log(resp);
        printToScreen(resp);
      }, function(err) {
        console.log(err);
      }
    );
  }

  function printToScreen(jsonObj) {
    var test = document.getElementById("test");
    test.innerHTML = JSON.stringify(jsonObj);
  }

  document.addEventListener("DOMContentLoaded", function(event) {
    start();
  });

Displaying the Results

In the index.html file, you can use the printToScreen JavaScript function to output the appropriate information stored within the resp tag. You stored the information into the resp tag through the queryRecord method in the main.js file.

The index.html uses this function to display the results to your MyInsights visualization.

This is a sample of the following code:

<h2 id="test"> </h2>

Packaging the MyInsights Visualization

  1. Compress the MyInsights visualization you created. This includes the index.html, main.js, q.js and MyInsights.js files.
  2. Ensure that you compress the files and not the directory containing your files. Folders should not be inside the zip file.
  3. Send the compressed .zip file to your company administrator.

General Use

All Where Clauses must use single quotes.

where: 'scale = 'week_vod' AND 'dataType' ='NRx' AND AccountId in {'id1', 'id2', 'id3'}'

Next Steps

You can further enhance reports using a variety of Javascript libraries, including Angular, React, and Vue.

See the Developer Release Notes for the most up-to-date information on MyInsights and other Veeva CRM APIs.