I have a spreadsheet collecting from multiple quizzes. Each varies in length and points available. I am using onFormSubmit trigger in my spreadsheet to copy relevant info (name, email, score) of the most recent submission over to another sheet for the next step of the workflow.
var score = inSheet.getRange(inRow, colNoScore).getValue();
This returns the value of "5", and not "5/10" as it is displayed in the spreadsheet.
How do I access not only the value of correct responses, but also the possible total so that I can create an average?
Instead of getValue() use getDisplayValue()
Reference
https://developers.google.com/apps-script/reference/spreadsheet/range#getdisplayvalue
Related
On Google form submission, I am trying to get a unique patient id in column A automatically whenever there is a response being submitted. You can also see the formula in the formula bar.
As of now, I am able to do it with the following google script but due to the trigger limit, it is not getting fulfilled as the COVID response is quite higher and requests are keep coming in.
function myFunction1() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var lr=sheet.getLastRow()
sheet.getRange(lr,1).setFormula('="PID"&row()-1');
}
If I add the formula to all cells in column A of this sheet, every time a new row is being inserted on form submission and the formula is NOT available for that row by default.
So, Is there a way that I can automate generating the PID automatically.? or any other smart ideas without the trigger option?
Alternative ARRAYFORMULA in cell A1:
=arrayformula({"Patient Unique ID #";if(B2:B<>"","PID"&row(A2:A)-1,iferror(1/0))})
"Patient Unique ID #" puts the title (Patient Unique ID #) in cell A1, then the ; returns the line.
If B is not empty then generate the unique ID as per "PID" and a unique number based on ROW() less 1. If B is empty, then nothing iferror(1/0).
In Google Sheets, this sort of thing is usually done with an array formula. I would recommend that you leave the 'Form Responses 1' sheet as is and insert the timestamps in a new sheet with something like this:
cell A1:
=arrayformula(
ifs(
row('Form Responses 1'!A1:A)) = 1, "Patient ID",
isnumber('Form Responses 1'!A1:A), row('Form Responses 1'!A1:A) - 1,
true, iferror(1/0)
)
)
cell B1:
={ 'Form Responses 1'!A1:Z }
If you absolutely want to insert the Patient ID column directly in the form responses sheet, you may want to place it on the right after the columns that get updated by the form.
An array formula is more reliable than using a function that runs on a trigger, but do note that the patient IDs will be dynamic and only remain valid as long as no rows are inserted or deleted in the data. The same is true with your current approach.
To get static IDs, use an on form submit trigger that writes an ID on a row when that row is first submitted. See the insertUniqueId_ script for one example — it runs on an on edit trigger, but can be modified to run on an on form submit trigger.
I've got a Google Form to enter deposits and withdrawals into a Google Sheet and then the ending balance is calculated so the user can balance their check book.
I'm trying to get the most recent balance to display on the Google Form by finding the last row with a balance that is in the 'Ending Balance' column.
It seems a script may be easiest but nothing seems to so what I need. Any advice or direction is appreciated.
Here's the sheet I have set up, it's connected to my form with the headers in row 2.
Google Sheet Image
You can
create a bound script attached to your destination spreadsheet
set up a installable trigger onFormSubmit that will fire every time a new form is submitted
access the newest form submission data with getLastRow()
Retrieve the values in column 11 (which contains your Ending balance)
Sample script:
function getMyBalance(){
var sheet=SpreadsheetApp.getActive().getActiveSheet();
var row=sheet.getLastRow();
var column=11;
var balance=sheet.getRange(row, column).getValue();
Logger.log(balance);
}
I'm a complete newbie to programming but wants to learn how. What I did is, I created a google form with 8 questions and the responses goes to a spreadsheet. Now what I want to do is to add another column on the spreadsheet, like a unique ID(should be a sequence like 10001, 10002, 10003, etc.) so I have a unique modifier, in that way once the form is submitted, that unique ID, will also increment by 1.
So far what I did is I created an array on the spreadsheet Unique ID column with this formula:
=arrayformula(if(row(A2:A)=1,"Unique ID",if(len(A2:A)>0,9999+row(A2:A),iferror(1/0))))
But, I don't know how to call the value on the google script editor. (example cell: I2 the value is 10001, I3 = 10002). Can you anyone help me with this please? Any help will be appreciated.
Getting your Id from the Form's Linked Sheet
function onFormSubmit(e) {
if(e.values && !e.values[1])return;//make question one a required question. This will keep you from sending emails due to spurious triggers.
var colnum='enter the column number of you id';//A=1,B=2...
var id=e.range.getSheet().getRange(e.range.rowStart,colnum).getDisplayValue();
}
Please note: You can not run a function like this from the Script Editor so to avoid the inevitable question I'll simply point out that this requires a trigger to test it. Or you have to figure out a way to provide it with an event object.
onFormSubmit Event Object
I have three Google Forms which submit data to different sheet in Spreadsheet. Google Forms write time stamp in first column when data is submitted. My triggered function send the email notification on submit data to spreadsheet from GForm. I need a different content of notification depending on the sheet of the spreadsheet where data is submitted.
I think about this:
get last update of spreadsheet
switch first sheet to action sheet
find the date equals the last update data in action sheet
if date is not founded, switch to next sheet and find last update date
...
...
if date is founded
get name of action sheet
send content-associated notification
So, think it's too difficult. Of course I can create many spreadsheet with many scripts and each script will send different notification, but it is not ergonomic.
Thank you!
In the event coming from your forms you can get the timeStamp and the row number where the response is recorded. With both criteria I guess it shoudn't be too hard to find the right sheet, just examine this row number in every sheet and compare the time values, if there is a match then you get it !
You can get the values in the eventinfo like this:
Logger.log('row = '+e.range['rowEnd'] + ' timestamp = '+e.namedValues['Timestamp'] )
I didn't test further so please update here is it worked as expected (or not).
Maybe you can add an onEdit trigger:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
var sheet_name = s.getName();
//you can also add a code to get row and col, timestamp, etc.
}
Note: haven't tested this code. I assume this is what you want.
I would like to create a Google Apps Script to do the following: When I select a cell containing the name of a person in a spreadsheet (a spreadsheet that records sales, for example), and use a menu button to call the function, the script does a search (a query) using the person's name (or number of his document) in another spreadsheet that stores complete consumer data and that contains all the information that I need from that consumer to generate a contract or a payment receipt.
What is the best strategy to implement this search for information from one spreadsheet in another spreadsheet using Google Apps Script?
Do you have some script sample with a implementation similar to this? THANK YOU in advance for any help/guidance!
There is no event triggered by a cell selection, you'll have to use a menu item or a button to call the function or, if it is acceptable for your use case, edit the cell to trigger an onEdit event.
The 'search part' is actually very simple, the data being on the spreadsheet itself or in another one has no importance, it will simply change the way you access data ( getActiveSpreadsheet or openById()). From there just get all the values and do a search in the resulting 2D array.
EDIT following your comment : here is an example of such a code that returns the range of the found cell (and we get the A1 notation but we could getValue() as well of course.).
function test(){ // to test the find function with an argument, 'any' in this case
var result = findItem('any');
if(result){Logger.log(result.getA1Notation())}else{Logger.log('no luck !')};
}
function findItem(item){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = ss.getDataRange().getValues()
for(var n = 0;n<data.length;++n){
if(data[n].indexOf(item)>-1){ // this is a "strict" find, ie the value must be the entire search item. If you want to do partial match you should compare differently...
return (ss.getRange(n+1,data[n].indexOf(item)+1)); // if found return the range. note the +1 because sheets have 1 index while arrays have 0 index
}
}
return false;// if we come to the end of sheet without result...
}