Question taking the source data from google sheet and as result on google script cannot have duplicate choices values - duplicates

i really new in this function or google apps . and i'm trying to do is make a google script to work for my google form, and the data is taken from google spreadsheet . at first is running just fine, until i input a same data than running the script is showing an error 'Error
Exception: Questions cannot have duplicate choice values' even a few blank row between the data in row, is also a 'duplicate values'
function isi_akbar() {
var id_form=FormApp.openById("1emH9-KTFtGcXPnWg47SJhhUDAwD-GO-k3u3sdMmrwl8");
var pilih_akbar=id_form.getItemById("202116860").asListItem();
var sheet_data=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("akbar");
var ambil_data=sheet_data.getRange(20,1,29).getValues();
pilih_akbar.setChoiceValues(ambil_data);
}
if there someone who can help me, if the script is running just ignore if there is a duplicate or even a blank rows between data . so my script can running just fine
this is the sample picture of my data that i want to ignore
my data sample
thats my question for now, i hope there is someone that can help me and solving my script . thank you before and have a good day for all

Related

Importfeed function not loading RSS feed entries sometimes

I have been using this sheet and many similar sheets for a long time but I have been facing this issue in many of the sheets. After a few days, the "importfeed" function stops loading the values on to the sheet. When I make a copy of the sheet (new spreadsheet), it instantly shows the values on the new sheet. It is a solution I do not want to use as I am using the script at different places and in that case I will have to change the script id everywhere. Please find the screenshot of the issue attached to this question below:
FYI, I am using a code to refresh the "importfeed" function every minute to get latest data. Any help would be great. Thanks

Getting gsheet Combo Charts to send them by email

This is my first question here, though I've had some helpful guidance from lots of questions before. I hope I don't miss anything important in this question.
I am currently writing a script in Google Apps Script to send some charts from a Google Sheets document by email, as images. My issue is that with Combined Charts, when I try to read them and get them as images, I get an error.
I've reduced the code to the minimum that will still throw the error I'm talking about.
function test_chart_fails(){
let gdoc_id = "xxxxxxxxxxxx";
let sheet_name = "test2";
let document = SpreadsheetApp.openById(gdoc_id);
let sheet = document.getSheetByName(sheet_name);
let charts = sheet.getCharts();
let chart = charts[2];
let inLineImages = {};
inLineImages["chartC"] = chart.getAs('image/png');
}
I get the following error:
Exception: Service Spreadsheets failed while accessing document with id xxxxxxxxxxxxxxxxxxxxxxxxxx.
test_chart_fails # AppsScriptFile.gs:305
Where 305 is the last line of my sample code (the one with 'chart.getAs').
Now some additional info that may be relevant (or not):
The sheet in question has 9 charts in total. I get this error if I try to access 7 of the 9, which are only the combined charts. Other charts will work fine, and I can put them in an email sent through MailApp. All the charts were created manually in the Gsheets document.
Regarding the data in the sheet that builds the charts, the sheet has 103 rows and 44 columns. All data in the sheet is formulas, not values.
I've searched for existing questions in this and other sites where this error message appears, but I didn't find a question where the error was related to Chart retrieval - specifically no instance related to Combo Charts. One instance mentioned an error related to the sheet size, so I mentioned the data size (rows x columns), but I don't think that is the issue - because the script runs fine for non-Combo Charts based on the same dataset.
Is this expected for combined charts? Is there a way I can 'retrieve' them and send them in an email like I do the others?
This appears to be a bug
https://issuetracker.google.com/182701055
SpreadsheetApp.getActive().getSheetByName().getCharts().getAs() returns this error: "Service Spreadsheets failed while accessing document with id" ... when the line chart has a right vertical axis
I would encourage you to go and star this issue to let Google know that it affects you and to subscribe to updates.
You are also encouraged to post any further reproduction steps and workarounds there if they haven't been mentioned yet.
Workaround you mentioned
How to obtain a correct image of a ComboChart with Google App Script?

How to protect the cell/range at the same time as appendrow

Im working on a website that stores data in a google spreadsheet and was wondering how I could use the appendrow() function and then protect that cell so no one can access it.
I'm new to google apps script and have been searching the internet for the last hour or so and can't find anything.
sheet.appendRow([text]);
But after that I would like it to get the value of that cell that was just written on so I could write:
var protection = the-row-just-written-on.protect()
I I am hoping for the result to be that no one can delete the text once it has been written on.

Error "Cannot find method insertChart(EmbeddedChartBuilder)" when using Apps Script to create Embedded Charts

I will like to take data from a spreadsheet "dataSheet" (shared with me as View only) to create a chart and output to my own spreadsheet "sheet".
I use Apps Script to create an embeddedChart and encountered this error: Cannot find method insertChart(EmbeddedChartBuilder).
I have followed Google's guide closely https://developers.google.com/apps-script/reference/spreadsheet/embedded-chart but can't resolve the error.
I have debugged step-by-step and realised the error happens at .insertChart (last line of code).
var chartBuilder = sheet.newChart();
chartBuilder.addRange(dataSheet.getRange('R'+earliestRowUsed + 'C1:R'+latestRowUsed + 'C1'))
.setChartType(Charts.ChartType.COLUMN)
.setPosition(5,5,0,0);
//collect data from dataSheet to add to Range.
for (indicator = 0; indicator < indicatorP.length; indicator++) {
indicatorIndex = indicatorList[0].indexOf(indicatorP[indicator]);
chartBuilder.addRange(dataSheet.getRange('R'+earliestRowUsed + 'C'+(dataCol + indicatorIndex) +':'+ 'R'+latestRowUsed + 'C'+(dataCol + indicatorIndex)));
}
chartBuilder.setMergeStrategy(Charts.ChartMergeStrategy.MERGE_COLUMNS); //join columns to create a table
chartBuilder.build();
sheet.insertChart(chartBuilder); //error takes place here.
I am open to using Charts or EmbeddedCharts to create my chart for my purpose (which is to take data from a shared view-only sheet to create a chart and embed in my sheet).
For working with Charts and Sheets, I found this Google guide https://developers.google.com/chart/interactive/docs/spreadsheets#embedding-achart-in-a-spreadsheet.
However the guide only shows a manual process to create Charts, and not with Apps Script. If anyone knows how, will appreciate your sharing as I haven't been able to find anything online.
Thank you.
I think your problem is the "View Only" permissions. Pretty sure that if you want to take data from a sheet programmatically and use it somewhere else you'll need to ask for Edit privileges.
After trialing a few scenarios, I found the problem to be due to EmbeddedCharts not being able to use data from another sheet file (view-only or owned). Using data from any sheets within the file EmbeddedCharts is to be created in works.

script to force republish of google spreadsheet

I have created a form that pushes data to a Google Spreadsheet. The data is latitude, longitude, location, and other identifying data. The spreadsheet is then published as a .CSV file and imported into ARC GIS to be displayed on an interactive map. It works exactly as I wanted and I set it to republish after each change.
The problem is that when the spreadsheet has rows appended by the script, it is not seeing it as a change and republishing. In order to get the updated data imported to the map, I need to go in and manually republish. Is there anyway through the Google Apps Script that I could make a few lines of code to force a republish? I could then add that to the "on form submit" script I have or another time based one that already runs at 3 am everyday.
I have looked through the Google Apps Script documents and not found anything. When searching for help on the web, the overwhelming majority of responses are for how to publish your script as a template for other.
My testing sheet was republished after the following function was executed by either a menu entry or a time-based trigger.
function ChangeIt() {
var sheet = SpreadsheetApp.getActiveSpreadsheet()
var t = new Date()
var x = 'upd: ' + t
var range = sheet.getRange('a3')
range.setValue(x)
}
If I were in your shoes, I'd add an extra column to the end of the sheet with some benign constant data that a script can change without affecting the systems consuming the data. If an extra column isn't an option, try modifying my sample to read in a current value, change it, and immediately change it back.
Also, I'd see if the spreadsheet onEdit() trigger fires when the form submit adds a new row. If so, tie your GAS function to it to force the republish. If not, setup a timed trigger to execute the GAS function.
A quick workaround for this issue that doesn't require scripting is to simply make an array copy of the data.
For example, I made a new tab and in A1 put this: =ArrayFormula('Form Responses 1'!A1:Z1000)
While the main Form responses tab will insert rows and not play nice with formulas this new tab stay nice and constant and updates automatically when new data is added.