Integrate ServiceNow with Google Sheets

salwaabedi
Tera Contributor

Can anyone provide what the steps will be and if there's a low code solution to this. We do not want to use any third party platform.

I am trying to integrating the ServiceNow (for example Business Applications table) into Google Sheets. The trigger would be that every time a user adds a new business application within ServiceNow table, a new row would be created in the Google Sheet automatically.

 

Thanks!

 

 

1 REPLY 1

Sankar N
Kilo Guru

You can integrate ServiceNow with Google Sheets using the ServiceNow REST API and Google Sheets API. The following steps will guide you through the process:

  1. First, you need to obtain the ServiceNow instance URL and API credentials (username and password). You can get this information from your ServiceNow administrator.

  2. Next, create a new Google Sheet or open an existing one.

  3. In the Google Sheet, go to the "Tools" menu and select "Script editor."

  4. In the script editor, paste the following code:

 

function getServiceNowData() {
  var serviceNowUrl = 'https://your-instance-url.service-now.com/api/now/table/business_application'; // Replace with your ServiceNow instance URL and table name
  var headers = {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'Authorization': 'Basic ' + Utilities.base64Encode('username:password') // Replace with your ServiceNow username and password
  };
  var options = {
    'method': 'get',
    'headers': headers
  };
  var response = UrlFetchApp.fetch(serviceNowUrl, options);
  var data = JSON.parse(response.getContentText());
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.clear();
  sheet.getRange(1, 1, data.result.length, Object.keys(data.result[0]).length).setValues([Object.keys(data.result[0])]);
  sheet.getRange(2, 1, data.result.length, Object.keys(data.result[0]).length).setValues(data.result.map(function(row) {
    return Object.keys(row).map(function(key) {
      return row[key];
    });
  }));
}

 

 

  1. Replace the ServiceNow instance URL and API credentials (username and password) with your own.

  2. Save the script and give it a name (e.g., "ServiceNow to Google Sheets").

  3. Run the script by clicking the "Run" button or going to the "Run" menu and selecting "getServiceNowData."

  4. The script will fetch data from the ServiceNow Business Applications table and populate the current sheet in the Google Sheet.

  5. To set up a trigger that automatically updates the sheet when a new record is added to the ServiceNow table, you can use Google Apps Script's time-driven triggers. Go to the "Edit" menu, select "Current project's triggers," and then click "Add Trigger." Set the trigger to run the "getServiceNowData" function every minute (or any other interval that you prefer).

This is a low-code solution that does not require any third-party platforms. However, it does require some basic knowledge of Google Apps Script and APIs.