Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const keyoptions = {
  2.   method: "GET",
  3.   headers: {
  4.     "Accept": "application/json+v6",
  5.     "x-api-key": "XXXXXXXXXXXXXXXXXXXXXXXXX"
  6.   }
  7. };
  8.  
  9. function getVRMData(row, column) {
  10.   const vrm = SpreadsheetApp.getActiveSheet().getRange(row, column).getValue();
  11.   const url = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' + vrm;
  12.   const response = UrlFetchApp.fetch(url, keyoptions);
  13.   const data = JSON.parse(response.getContentText())[0].motTests;
  14.   // extract info from reply
  15.  
  16.   const rows = data.map(function(d) { return d.expiryDate; });
  17.   const resultRows = data.map(function(d) { return d.testResult; });
  18.   const rfrAndCommentsRows = data.map(function(d) { return d.rfrAndComments; });
  19.   return {
  20.     "rows": rows,
  21.     "resultRows": resultRows,
  22.     "rfrAndCommentsRows": rfrAndCommentsRows
  23.   };
  24. }
  25.  
  26. const ss = SpreadsheetApp.getActiveSpreadsheet();
  27. const sheet = ss.getActiveSheet();
  28. const destSheet = ss.getSheetByName("customfunction");
  29. destSheet.getRange('A4:F').clearContent();
  30. const lastRow = destSheet.getLastRow();
  31.  
  32. for (var row = 2; row <= 10; row++) {
  33.   var data = getVRMData(row, 1);
  34.   const rows = data['rows'];
  35.   const resultRows = data['resultRows'];
  36.   const rfrAndCommentsRows = data['rfrAndCommentsRows'];
  37.   sheet.getRange(lastRow + row, 1, rows.length, 1).setValues(rows);
  38.   sheet.getRange(lastRow + row, 2, resultRows.length, 1).setValues(resultRows);
  39.   sheet.getRange(lastRow + row, 3, rfrAndCommentsRows.length, 1).setValues(rfrAndCommentsRows);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement