2

I need to send data of my spreadsheet to an other server, I've tried this.I am not getting error but its not working too.

I tried lots of things but no joy.

var ss  = SpreadsheetApp.getActiveSpreadsheet();
function onOpen() {
  var menuEntries = [ {name: "Send to PLM", functionName: "email"} ];
  ss.addMenu("MyMenu", menuEntries);
}

function email() {
 //Browser.msgBox("Hello World");
  //var url = "http://********/noetic_Data/AddDataToAras?data="; 
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var columns = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var numColumns = rows.getNumColumns();
  var values = rows.getValues();
  for (var i = 0; i <= numRows - 1; i++) {
    for (var j = 0; j <= numColumns - 1; j++) {
      var row = values[i][j];
      var cell = sheet.getRange(i+1,j+1);
    }
  }
  Logger.log(numRows+"::"+numColumns);
  var excelData = "";
  for(var k=0;k<values.length;k++)
  {
    if(excelData == "")
    {
     excelData = values[k]; 
    }
    else
    {
      excelData = excelData +"|"+ values[k]; 
    }
  }
  
   Browser.msgBox(excelData) ;
  return excelData;
   //var url = "http://*****/noetic_Data/AddDataToAras?data="+excelData; 

   var response = UrlFetchApp.getRequest("http://******/noetic_Data/AddDataToArasdata=", excelData)
   //fetch("******/noetic_Data/AddDataToAras?data=", excelData);
Logger.log(response.getContentText());
   
 // s = s+excelData;
 //return s;

}

4
  • Not enough info in this question yet, so you need to do some more work. getRequest() will show what the fetch would look like IF it was sent - but you haven't shown what you're getting. Your options value is a string, but should be an object with specific names properties - the string is an object, everything in JavaScript is, it's just missing properties that would end up in the GET request. Set muteHttpExceptions : true in the options for fetch so you can capture the response and examine it. Commented Jun 19, 2015 at 18:01
  • thanks Rohil for reaching me, but i got the solution... Commented Jun 21, 2015 at 12:21
  • If you have a solution that could help others, you can answer your own question. Commented Jun 21, 2015 at 12:43
  • yeah sure, will do... Commented Jun 23, 2015 at 14:09

1 Answer 1

1

var ss  = SpreadsheetApp.getActiveSpreadsheet();


function onOpen() {
 var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var columns = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var numColumns = rows.getNumColumns();
  var values = rows.getValues();
  for (var i = 0; i <= numRows - 1; i++) {
    for (var j = 0; j <= numColumns - 1; j++) {
      var row = values[i][j];
      var cell = sheet.getRange(i+1,j+1);
    }
  }
  var excelData = "";
  for(var k=0;k<values.length;k++)
  {
    if(excelData == "")
    {
     excelData = values[k]; 
    }
    else
    {
      excelData = excelData +"|"+ values[k]; 
    }
  }
  //Bowser.msgBox(excelData) ;     //***to view data on browser****
  

  var shUi = SpreadsheetApp.getUi();
  var app = UiApp.createApplication().setTitle('Custom functions');
  var panel = app.createVerticalPanel().add(app.createHTML('Click the button bellow to send data to PLM')
  .setStyleAttribute('padding','10px'));
  var grid = app.createGrid(1,2).setWidth('200');
  var b1 = app.createButton("send to PLM");
  var link = app.createAnchor('XXXXX',"http://***.**.*.***/noetic_Data/AddDataToAras?data="+excelData).setStyleAttributes({'zIndex':'1' , 'position':'fixed' , 'top':'45' , 'left':'20', 'color':'transparent' }).setTitle('proceed in a new tab');
  var G1 = app.createVerticalPanel().add(b1).add(link);
   grid.setWidget(0,0,G1);
  app.add(panel).add(grid)
  shUi.showSidebar(app);
 }

Sign up to request clarification or add additional context in comments.

1 Comment

Good... but better if it included an explanation of what the necessary change was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.