Status Update
Comments
mu...@google.com <mu...@google.com>
mu...@google.com <mu...@google.com> #2
This has been fixed internally and will be avilable in Fragment 1.3.0-alpha08.
Note: this fix relies on using the
ad...@amm-brasil.com <ad...@amm-brasil.com> #3
I search for a little more in this case, making others tests and I found the problem.
This is really a Bug, because I can make this process run if I fill the the Array with all columns value defined, like ["Column 01","Column 02", "Column 03"]
But it's not possible to send a Response for a GridItem with a empty values (null values) for rows that do not have values defined, even if the property SetRequired of the GridItem is set to false .
In that case is not mandatory to have one value set for each row, but the function createResponse still trow a error (when values like [null, null "Column 02",null] is provide to that function).
I send bellow a code in order to show the bug:
var formTeste = FormApp.openById("1nSGjp0JvFI4n0UAVu7it7JJ4nA2viup3Z0HAmQrRU6I");
const skipTypes = [ FormApp.ItemType.SECTION_HEADER, FormApp.ItemType.PAGE_BREAK ];
var items = formTeste.getItems();
for (var i = 0, retItems = []; i < items.length; i++) {
var item = items[i], type = item.getType();
if (skipTypes.includes(type) > 0) {
continue;
}
switch (type) {
case FormApp.ItemType.TEXT: item = item.asTextItem(); break;
case FormApp.ItemType.GRID: item = item.asGridItem(); break
default:
Logger.log("Warning: Question '" + item.getTitle() + "' has unsupported type " + type + ". It will be skipped.");
item = null;
break;
}
retItems.push(item);
}
var itemsForm = retItems;
var membersImport = [["Pergunta Teste","Produto Teste"],
["Resposta Teste",["Nenhum","02 Itens","Nenhum","04 Itens","Nenhum"]]];
for (var row = 1; row < membersImport.length; row++) {
try {
var responseForm = formTeste.createResponse();
for (var i = 0; i < itemsForm.length; i++) {
var resp = membersImport[row][i];
var item = itemsForm[i];
if (resp == "" || item === null)
continue;
var type = item.getType();
try {
Logger.log("item: " + item.getTitle() + " || " + type.toString() + " || " + resp);
} catch (exc) {
Logger.log("Erro: "+exc+" || item: " + membersImport[row][i] + " || " + type + " || " +
resp + " || row: " + (row+1).toString() + " || column: " + (i+1).toString());
throw exc;
}
if (item) {
var respItem = item.createResponse(resp);
responseForm.withItemResponse(respItem)
}
}
responseForm = responseForm.submit();
} catch (exc) {
Logger.log("Error: import the response: " + (row+1).toString()+" - "+exc);
throw exc;
}
}
I create a sigle form with two fields (one TEXT and one GRIDITEM), the GridItem have SetRequired set to no, so if I leave one row with value null should be run with no problem, but its not what happened !!!
Please, run this code and you see that works, but if you try to change the follow line to null values, you will see the error:
var membersImport = [["Pergunta Teste","Produto Teste"],
["Resposta Teste",[null,"02 Itens",null,"04 Itens",null]]];
In the documentation of this function will can se the description saying the is allowed to set null values if the row does not have any response assigned:
createResponse(responses)
Creates a new ItemResponse <
I wait for your reply again and hope you can understand and make the correction in the function in order to solve this bug.
Thank you again for your help and support !!!
Best Regards,
Mr. Marcelo Facioli.
mu...@google.com <mu...@google.com>
mu...@google.com <mu...@google.com> #4
Thank you for the additional details provided and I apologize for the confusion. I will do some research and come back to you with regards to this.
In the meantime, would you mind sharing a screenshot of how the grid question looks like? Please avoid sharing any personal information.
ad...@amm-brasil.com <ad...@amm-brasil.com> #5
Thank you for you reply.
As you asked I attached three images from the Test Form.
The first imagem show the edit template of the form, with two fields available (one Simple text and other GridItem).
The second imagem show a response enter manually, leaving some rows with no answer (as the Grid allows), this operation it's not possible to do with Script, using the method createResponse() because return a error with message of a invalid response submitted to grid question.
The third imagem show the form full filled with method createResponse() and call after a submit(), this works, but as I told, you have to provide one value to every rows, so no NULL values in array should be present (as the GridItem and Form allows) in order to work.
Waiting for your replay.
Best regards,
mu...@google.com <mu...@google.com> #6
Thank you for getting back to them. It seems that none of the images have gotten attached properly. Would you mind adding them again from the Issue Tracker itself?
ad...@amm-brasil.com <ad...@amm-brasil.com> #7
Sorry for delay in reply your message.
I attach again the three images from the Issue Tracker and I think it's ok now.
Waiting for any news.
Best regards.
mu...@google.com <mu...@google.com> #8
Thank you very much for the valuable information provided and for the patience regarding this report.
I have been able to reproduce this accordingly and I have forwarded this behavior internally.
Any updates regarding this shall be posted here.
Best regards
pe...@gmail.com <pe...@gmail.com> #9
is...@google.com <is...@google.com>
mi...@google.com <mi...@google.com> #10
Hi!
This issue has been fixed.
If you start encountering this behavior in the future, please create a new issue.
Thank you.
Description
I'm current building one application over the Google Form Plataform, using App Scritps.
I need to remove and add new responses to a form , because unfortunetly there is no way to update Responses in a form, using Script, only with manually edit from a link, when a form allows changing.
But the problem when I create a new Response (on the form), al the questions with Type = GRID, does not allow to insert a responses, (witch is a copy) from other response of the same form.
Every time a try to execute the "item.createresponse(arr_param_string)", I get the same error result, I already tried a lot of different ways, in order to pass the simple String Array, like informed on documentation of the function.
I'm using a simple Array of String with 9 members (8 null and just one with value), like this :
var newResponse = objForm.createResponse();
var itemsForm = objForm.getItems();
for (var cont = 0; cont < itemsForm.length; cont++) {
var item = itemsForm[cont], resp = "";
if (item == null)
continue;
if (item.getType() == FormApp.ItemType.GRID) {
var resp = Array(0);
var titleGrid = item.getTitle();
item.getRows().map((value,idx) => {
var titleGridRow = titleGrid+" ["+value+"]";
resp.push((objSave[titleGridRow] != "" ? objSave[titleGridRow] : null));
});
// the Array return is something like that : resp = [ null,null,null,null,null,null,"02 Itens",null ]
var respItem = item.createResponse(resp);
newResponse.withItemResponse(respItem)
The error I get is the following:
"Exception: Invalid response submitted to grid question"
Could you please help me, what a have to do, in order to get the code work ?
I wait for your answer as quickly as possible.
Best Regards,
Mr. Marcelo Facioli