I have a google sheet (named "Template") which I use to capture client data. Data entry cells in this "Template" sheet are not arranged in a sequential manner due to the way that the template is designed. I have a code to save this data to a second google sheet serving as my database( named "Data"). I am writing a code to search the saved client records from "Data" by client unique identifier (client ID). After running the client record search function, I expect the data to be populated back to the original "Template". I can't seem to find an efficient way of achieving this using google apps script. The "Data" sheet will be having up to 50 columns of data per client.
Below is the code that I wrote. The code works as expected but I feel it's a long way of doing it and there might be a better and shorter way of achieving this when dealing with upwards of 50 columns per client. Is there a way to copy the entire row in "Data" sheet and paste the respective values to the range/array (["D3", "B1", "B2", "E2", B4",...] as in example below) in "Template" sheet using few lines of code, as opposed to setting value for each and every one of the 50 cells? Am still new to coding.
var ss = SpreadsheetApp.getActiveSpreadsheet();
templateS = ss.getSheetByName("Template");
dataS = ss.getSheetByName("Data");
//function to retrieve client record and populate template
function searchRecord()
var searchCell = templateS.getRange("B6"); //cell holding the search value
var searchValue = searchCell.getValue(); // value to be used to search. Unique client ID.
// Search record in data sheet using unique client ID
var recordFound = dataS.getRange("A:A") //client ID in column A of "Data"
.createTextFinder(searchValue)
.matchCase(true)
.matchEntireCell(true)
.findNext();
var row = recordFound.getRow(); //capture row position containing the search value.
//**populate template with up to 50 lines of below code**
templateS.getRange("D3").setValue(dataS.getRange(row, 1).getValue()); //capture client ID
templateS.getRange("B1").setValue(dataS.getRange(row, 2).getValue()); //capture title
templateS.getRange("B2").setValue(dataS.getRange(row, 3).getValue()); //capture surname
templateS.getRange("E2").setValue(dataS.getRange(row, 4).getValue()); //capture first name
templateS.getRange("B4").setValue(dataS.getRange(row, 5).getValue()); //capture address
}