0

I have a code written code.gs of Google App script like this

function enterAmount(inputInfo){
  var url = 'https://docs.google.com/spreadsheets/d/1bM8l6JefFsPrlJnTWf56wOhnuSjdIwg3hMbY1tN1Zp8/edit#gid=1151242353';
  var ss = SpreadsheetApp.openByUrl(url);
  var ws = ss.getSheetByName("Payment Configuration");
  
  var repeatedPayment = ( inputInfo.amount / 50 );
  for(var i = 50; i <= repeatedPayment; i++){
           ws.appendRow([inputInfo.uname,inputInfo.pm_hseno,inputInfo.streetName]);
  }
}

The function is working fine but I just want to append the information starting from column E. I dont want it follow the last column of the whole sheet. Can anyone help me modify the code? Thanks in advance.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • From your replying of `Okay I explain clearly from beginning. I actually wanted the code to copy the username, house number and street to the google sheet in worksheet "Payment Configuration" from the column E. I give the link to my web app now. I have used my coding first to let you understand how I expected the things to be. The username is going to be Username : Mathavan Password : Apple so after logging in you enter 16.jlnsanggul4. After you click submit, you can increase the payment by 50. Let say the payment now I specified into RM 100 so it should copy username, housenumber and street.` – Tanaike May 24 '21 at 07:41
  • and `And if it is RM 100, it will copy twice the username, house number and street to my google sheet. Have I made my self clear now`, unfortunately, I cannot understand about your situation. So, in this case, my answer might be not useful for your situation. By this, in the current stage, I would like to delete my answer. When I could correctly understand about your question and could find the solution, I would like to answer it. – Tanaike May 24 '21 at 07:41
  • And about your additional replying of `Sorry about the new question. I am quite rushing to complete my project. But I really apologize for what I have done.`, I understood `I am quite rushing to complete my project.`. In this case, I think that I might not be able to resolve your question soon. This is due to my poor skill. I deeply apologize for this. I think that I have to study more. – Tanaike May 24 '21 at 07:41
  • @Tanaike No no. For now only you are helping me thank you for the help you are giving me now. Yeah I am rushing but I wont force you. I try to do here at the same time I would like to hear from you also as you actually have the experience. I learnt alot of things about google appscript from your GitHub. It was really helpful for me. So if can please help me too. – Mathavan Krishnan May 24 '21 at 07:45
  • Thank you for replying. From `I am rushing but I wont force you.`, although I cannot hold responsible for your project, when I could correctly understand about your question and find the clear solution, I would like to answer it. I deeply apologize I cannot resolve your question soon. – Tanaike May 24 '21 at 07:48
  • @Tanaike thank you so much for kindness again. I will let you know if I managed to do it. Hope you can help me with this and embedding the web app. Thank you so much for your help. – Mathavan Krishnan May 24 '21 at 07:51
  • 1
    Could you please clarify why Tanaike's answer is not working for you? Consider providing a copy of the spreadsheet you are working on (free of sensitive information), where the desired outcome is clearly indicated. – Iamblichus May 24 '21 at 08:11

1 Answers1

2

If you want to append row based on your last row in column E you can use getRange() last column and getDataRegion() instead.

I'm not sure what is your for loop is for though.

function enterAmount(inputInfo){
  var url = 'your URL';
  var ss = SpreadsheetApp.openByUrl(url);
  var ws = ss.getSheetByName("Payment Configuration");
  var lastRow = ws.getRange("E1").getDataRegion().getLastRow() + 1;

  
  var repeatedPayment = ( inputInfo.amount / 50 );
  ws.getRange(lr,1,1,3).setValues([[inputInfo.uname,inputInfo.pm_hseno,inputInfo.streetName]]);

 
}
Asyraf Syahmi
  • 127
  • 1
  • 1
  • 7