Anyone who can help me out to explain why it is that when I save a record on a form it creates a double record but one of them is always blank.
If you need any other information I will gladly share. I do have an attachment field on the form that send the attachment to the blank record and not the record with the actual data.
UserRec.AddNew
UserRec("DATECAPTURED").Value = Now
UserRec("FULLNAMES").Value = Me.cboFullNames
UserRec("EMPLOYEENUMBER").Value = Me.txtEmpNum
UserRec("INSTITUTENAME").Value = Me.cboInstituteName
UserRec("COURSENAME").Value = Me.cboCourseName
UserRec("COURSENAMESUB").Value = Me.cboCourseSub
UserRec("DATESTARTED").Value = Me.DATESTARTED
UserRec("DATEFINISHED").Value = Me.DATEFINISHED
UserRec("INSTRUCTOR").Value = Me.txtInstructor
UserRec("RESULTS").Value = Me.cboResults
UserRec("CERTIFICATEOBTAINED").Value = Me.Combo115
UserRec.Update
Thank you
Related
I am writing a form to update an inventory whenever an item is ordered. In this project, there is a google sheet which is linked to a form. The form contains a script that gets the current inventory from the sheet and subtracts one from this upon order.
The form has three questions: name, size, and comment.
The issue I am getting is that the system works once, and then somehow stores the first response for each successive form submission.
For a minimal working example: I've distilled the issue to the following code, which is triggered by a form submission:
function updateStock()
{
var customer_name = "";
const ss_id = ### I enter spreadsheet ID here ###
const form_id = ### I enter form ID here ###
var sheet = SpreadsheetApp.openById(ss_id);
var form = FormApp.openById(form_id);
var form_resp = form.getResponses()[0];
var customer_name = form_resp.getItemResponses()[0].getResponse();
Logger.log(customer_name);
// Rest of code follows from here
}
Upon entry for the first form I write:
Name: Peter
Size: M
Comment: none
Code returns:
1:43:40 AM Info Peter
(If I include the rest of the code, it correctly subtracts the inventory).
Then on the next (or tenth) submission, I might submit:
Name: Joe
Size: L
Comment: none
again, the code returns:
1:44:55 AM Info Peter
If I start from scratch or clear responses, I can get it to work once, but if not, the code will forever return "Peter" for the name, regardless of what I enter.
The form responses however are correct! It is just the call to
var form_resp = form.getResponses()[0];
var customer_name = form_resp.getItemResponses()[0].getResponse();
... that seems to have a "cached" value.
This seems like a weird bug, but am wondering if anyone has a clue as to what this might be (or, honestly, if there is a better way to achieve the same result!)
Thanks for taking the time.
Ugh. Very bad error on my part.
As vector pointed out:
The code: form.getResponses() returns all responses whereas I thought it was returning the current response (read the docs!)
Thus form.getResponses()[0] was naturally returning the first answer, whereas I should have written:
var N = form.getResponses().length-1;
var form_resp = form.getResponses()[N];
Whoops.
I have a sheet which is populated by an expenses form.
Each time the form is submitted, a new row is created in the spreadsheet.
I also have a small script, which I run on the first of the month to add a few lines to the same sheet (some regular expenses that don't need me to use the form).
This all works fine.
The problem is that after I run the script (which adds about 5 lines to the sheet), when I go back the form, and submit it. New entries are being put ahead of the scripts ones.
So:
1) Submit expenses form -> new entry in row 2.
2) submit expenses form -> new entry in row 3.
3) run script -> new entries in rows 4,5,6,7,8,9
4) submit expenses form -> new entry in row 4. Rows 4,5,6,7,8,9 shift down one
Can anyone advise?
Why is this happening ?
Actually, I think google form internally keeps a track of last row number where it have inserted your response. So that next time it can decide where to put your new response.
So when you're manually[by script] entering data in sheet and not through google form so the counter of google form row number is not updated and that's unaware of the fact that you have inserted some data, so it tried to insert data at the same position that it remembers.
Hope this will help you, at least to some extend.
How to solve this ?
Solution to your situation would be, as mentioned in another answer; you can use the FormService to submit your data as "form responses" and thus the google form internal counter also increases it's count. Everything is in sync.
Since your script is not doing any manipulations to the data, but simply adding recurring values to the form, use the Forms Service to submit your data to the form directly as responses. With this approach, the expenses will all live within the Form responses in case you ever disconnect the form from the sheet.
function addRecurringExpenses() {
var form = FormApp.openById("FORM_ID");
// Create an array of objects where each object represents one of your recurring expenses.
// The key-value pairs correspond to the questions in the fom
var recurringExpenses = [{"question1": "1-response1", "question2": "1-response2", "question3": "1-response3"},
{"question1": "2-response1", "question2": "2-response2", "question3": "2-response3"},
{"question1": "3-response1", "question2": "3-response2", "question3": "3-response3"}]
var questions = form.getItems(); // Get all of the questions in the form
for (var i=0; i<recurringExpenses.length; i++) { // Loop through the recurring expense
var response = form.createResponse(); // Create a new response that will house all of the answers for this one expense
var question1 = questions[0].asTextItem(); // Not all questions are "TextItems" – https://developers.google.com/apps-script/reference/forms/
var answer1 = question1.createResponse(recurringExpenses[i]["question1"]);
var question2 = questions[1].asTextItem();
var answer2 = question2.createResponse(recurringExpenses[i]["question2"]);
var question3 = questions[2].asTextItem();
var answer3 = question3.createResponse(recurringExpenses[i]["question3"]);
// Add each answer to the response object
response.withItemResponse(answer1).withItemResponse(answer2).withItemResponse(answer3);
response.submit(); // Submit the response to the form
}
}
I am creating a submission document through Google Forms & Google Spreadsheets. I have created a form that emails data for approval. The email includes a URL link which is contains a unique ID. This link is connected to a second form for approval/denial of the submission. I am having difficulty getting this unique ID linked to the approval/denial process form. I believe I need to reference this ID so that it will approve the correct entry in my spreadsheet. Can someone point me in the right direction on how to reference my ID through my second form or give me another idea on how to do this?
var d = new Date();
var ID = d.getTime();
approvalLink = "docs.google.com/forms";
approvalLink = approvalLink + "?id=" + ID
Unfortunately, there is no way to do this on the live forms. Form Script code doesn't run until after the form is submitted.
However you could generate a pre-filled form url for the 2nd approval/denial form that fills in a question with your ID (PS. Think about using a UUID instead of timestamp).
var form = FormApp.openById("2nd Form ID");
var response = form.createResponse();
var items = form.getItems();
var item = items[0].asTextItem();
var itemResponse = text.createResponse('my text');
response.withItemResponse(itemResponse);
var url = response.toPrefilledUrl();
You use this url to present a form with that questions that already has your ID filled in. Then when your 2nd form is submitted you can reference that question.
The url this generates will end in something like: ?entry.2623445234=SomeText.
I have a google-form that has the following two fields:
Email address: - A text box
Tool: - A radio button
Tool 1
Tool 2
Tool 3
The user would enter his email address and select a tool and click submit. I would like the following message to appear:
Thanks for responding. An email has been sent to you to at entered email address to download selected tool.
I have the following piece of code in the script editor
function emailFormSubmission() {
var form = FormApp.getActiveForm();//the current form
var dest_id = form.getDestinationId(); //the destination spreadsheet where form responses are stored
var ss = SpreadsheetApp.openById(dest_id);//open that spreadsheet
var theFormSheet = ss.getSheets()[0]; //read the first sheet in that spreadsheet
var row = theFormSheet.getLastRow(); //get the last row
var emailid = theFormSheet.getRange(row,2,1,1).getValue();//get column 2 corresponding to the email id. column 1 is timestamp. so, skip that.
var tool = theFormSheet.getRange(row,3,1,1).getValue();//get column 3 corresponding to the selected tool.
form.setConfirmationMessage('Thanks for responding. An email has been sent to you '+ emailid + ' to download' + tool);
}
I have also set the triggers to be Run -> emailFormSubmission, Events -> from Form , onFormSubmit.
What happens is: Suppose the first user ('A') enters his information and clicks submit. His entered information gets displayed correctly. When second user ('B') enters his information and clicks submit, A's information is displayed. When third user ('C') enters his information and clicks submit, then B's information is displayed. I found that the issue is with "getlastrow()" since the spreadsheet is updated after emailFormSubmission is processed.
Whats wrong with the above code? How do I fix this?
UPDATE
Based on #wchiquito's comments, I changed the code to following to make it work.
function emailFormSubmission(e) {
var form = FormApp.getActiveForm();
//Check this link on how to access form response:
//https://developers.google.com/apps-script/understanding_events?hl=en
var responses = e.response;//e is of type formresponse.
var emailid = responses.getItemResponses()[0].getResponse();
var tool = responses.getItemResponses()[1].getResponse();
Logger.log(emailid);
Logger.log(tool);
form.setConfirmationMessage('Thanks for responding. An email has been sent to '+ emailid + ' with instructions to download ' + tool +'. If you do not find our email in your inbox, please check your spam folder');
Logger.log(form.getConfirmationMessage());
}
Remember that the event On form submit (Understanding Events) receives a parameter that has the following structure:
values
range
namedValues
and you can do something like:
function emailFormSubmission(e) {
...
var row = e.range.getRow();
...
}
Try the following code to observe the structure of the parameter e:
function emailFormSubmission(e) {
...
Logger.log(e);
...
}
UPDATE
First, excuse my confusion, I showed you the structure of a Spreadsheet form submit event when you really are using a Form submit event.
Sure enough, a Form submit event has the following structure:
response
Returning an object of type FormResponse.
Therefore, defining the event: On submit form (Form submit event), you can do something like the following:
function emailFormSubmission(e) {
var itemResponses = e.response.getItemResponses();
for (var i = 0, len = itemResponses.length; i < len; ++i) {
Logger.log('Response #%s to the question "%s" was "%s"',
(i + 1).toString(),
itemResponses[i].getItem().getTitle(),
itemResponses[i].getResponse());
}
}
However, the confirmation message set according to the data sent as responses of the form, does not seem very clear, you can set the message, but will not display for the active response, if not for the next.
My first guess is these two lines right here:
var emailid = theFormSheet.getRange(row,2,1,1).getValue();//get column 2 corresponding to the email id. column 1 is timestamp. so, skip that.
var tool = theFormSheet.getRange(row,3,1,1).getValue();//get column 3 corresponding to the selected tool.
When you call getLastRow() on a sheet - you're getting the last row. Sure, but considering the order of events and how these values are processed, you need a +1, to get the most recent submission. Currently you're one row behind when your code runs to update the Form confirmation message.
So just change your code to the following:
var emailid = theFormSheet.getRange(row+1,2,1,1).getValue();
var tool = theFormSheet.getRange(row+1,3,1,1).getValue();
Spreadsheets are the most confusing of Google services, in my opinion. When you get values in the Spreadsheet, they're returned as an [] or [][] depending on what your Range is when you call getValues(). But getRange() on a sheet starts at index 1 (to make it easier to read in code I suppose). Often times I find that I have an off-by-one error because of the way data is passed around. Just keep that in mind as you work with Spreadsheets :)
Short answer: want you want can't be done with Google forms.
Explanation:
form.setConfirmationMessage() sets the confirmation message for the form as stored on the server, not for the current active form. Same applies for example for form.setTitle(). The active form will not be modified. One would expect different behaviour for the confirmation message, but alas, this is not the case.
Yes, you can do this with the add-on "Formfacade".
It's free to use in 1 form.
var BikeOrder = (from s in dbobject.TblBikesOrders
where s.BONo == searchint
select new {s.BOId,s.BONo,}).ToArray();
rptBikeOrder rptobject = new rptBikeOrder();
rptobject.SetDataSource(BikeOrder);
crystalReportViewer1.ReportSource = rptobject;
how can i fix it. where s.BONo == searchint why not working
Put the fields in the details section of the report