Google Apps Script Error Exception: Questions cannot have duplicate choice values - forms

keep getting this annoying error, tried making a new sheet and new form and issue is repeating itself
Nov 8, 2022, 1:08:30 PM Error Exception: Questions cannot have duplicate choice values.
at [unknown function](Code:21:27)
at [unknown function](Code:11:30)
at populateQuestions(Code:10:14)
at openForm(Code:3:3)
The script used from YouTube link
function openForm(e)
{
populateQuestions();
}
function populateQuestions() {
var form = FormApp.getActiveForm();
var googleSheetsQuestions = getQuestionValues();
var itemsArray = form.getItems();
itemsArray.forEach(function(item){
googleSheetsQuestions[0].forEach(function(header_value, header_index) {
if(header_value == item.getTitle())
{
var choiceArray = [];
for(j = 1; j < googleSheetsQuestions.length; j++)
{
(googleSheetsQuestions[j][header_index] != '') ? choiceArray.push(googleSheetsQuestions[j][header_index]) : null;
}
//item.asMultipleChoiceItem().setChoiceValues(choiceArray);
// If using Dropdown Questions use line below instead of line above.
item.asListItem().setChoiceValues(choiceArray);
}
});
});
}
function getQuestionValues() {
var ss= SpreadsheetApp.openById('1jVxeFFi8LxHGUJ2L3suzjf9iokZN2RI5Vu1hcGCOWrc');
var questionSheet = ss.getSheetByName('Static');
var returnData = questionSheet.getDataRange().getValues();
return returnData;
}
tried to follow the tutorial https://www.youtube.com/watch?v=PRJ4bKk9JE8&t=268s

Related

Word web addin load whole document from server header/footer

We are trying to load a word document from server using JavaScript. We send the document using a base64 encoding. With our current approach, only the body is loading using the function:
context.document.body.insertFileFromBase64(fileContent, "replace");
Unfortunately, the header and the footer are not loading. Is there another approach to load the whole document including body and footer?
the insertFile operation does not overwrite existing header/footers in the document.
According to my research, I saw this article for using insertFileFromBase64.The article says," if you use insertFileFromBase64 to insert the file it does have this blank page with header and footer." Did you have the same issue for this?
However, another article says it's a design issue. Userform will encode data and will create an appointment on Microsoft Outlook Calendar
The article provides approach:
function getFile(){
Office.context.document.getFileAsync(Office.FileType.Compressed, { sliceSize: 4194304 /*64 KB*/ },
function (result) {
if (result.status == "succeeded") {
// If the getFileAsync call succeeded, then
// result.value will return a valid File Object.
var myFile = result.value;
var sliceCount = myFile.sliceCount;
var slicesReceived = 0, gotAllSlices = true, docdataSlices = [];
console.log("File size:" + myFile.size + " #Slices: " + sliceCount);
// Get the file slices.
getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docdataSlices, slicesReceived);
}
else {
app.showNotification("Error:", result.error.message);
}
});
}
function getSliceAsync(file, nextSlice, sliceCount, gotAllSlices, docdataSlices, slicesReceived) {
file.getSliceAsync(nextSlice, function (sliceResult) {
if (sliceResult.status == "succeeded") {
if (!gotAllSlices) { // Failed to get all slices, no need to continue.
return;
}
// Got one slice, store it in a temporary array.
// (Or you can do something else, such as
// send it to a third-party server.)
docdataSlices[sliceResult.value.index] = sliceResult.value.data;
if (++slicesReceived == sliceCount) {
// All slices have been received.
file.closeAsync();
onGotAllSlices(docdataSlices);
}
else {
getSliceAsync(file, ++nextSlice, sliceCount, gotAllSlices, docdataSlices, slicesReceived);
}
}
else {
gotAllSlices = false;
file.closeAsync();
console.log("getSliceAsync Error:", sliceResult.error.message);
}
});
}
function onGotAllSlices(docdataSlices) {
var docdata = [];
for (var i = 0; i < docdataSlices.length; i++) {
docdata = docdata.concat(docdataSlices[i]);
}
var fileContent = new String();
for (var j = 0; j < docdata.length; j++) {
fileContent += String.fromCharCode(docdata[j]);
}
var mybase64 = window.btoa(fileContent);
console.log("here is the base 64", mybase64);
// Now all the file content is stored in 'fileContent' variable,
// you can do something with it, such as print, fax...
}

Export Email-adress from a label in Gmail using Apps Script

Hi im trying to export the Emailadresses from the senders in a label in Gmail Called "Suarez". But it's just running and never completing, it should be about 372 emails. Is it to much to print to the logger?
Here is what im trying:
function getEmailsadresses(){
var threads = GmailApp.search("in:suarez");
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var m = 0; m < messages.length; m++) {
var msg = messages[m].getFrom();
}
}
Logger.log(msg()); // log from address of the message
}
I use a script embedded in an spreadsheet the reads every messages in every threads in a Label that could probably be a good starting point for you.
My specific use case was to log SMS messages that my android phone sends me as emails each time I send or receive a text message.
So it will work for you by just changing the label name and maybe remove the data filtering I added on the message. Since I have a lot of data I set up a time trigger task manager to works in small bunches to avoid exceeding time limit.
Usage is simple : run the "startSMSLog" and go have a couple of coffees until the cell A1 in the spreadsheet stops being RED... that's it.
Code below : the start function
function startSMSLog(){
var triggerID = ScriptApp.newTrigger('countSMSLogEmails').timeBased().everyMinutes(5).create().getUniqueId();
var thisTrigger = PropertiesService.getScriptProperties().setProperty('thisTriggerSMS',triggerID);
PropertiesService.getScriptProperties().setProperty('current thread SMS',0);
var sh = SpreadsheetApp.getActive().getSheetByName('SMS'); // change to the name of your sheet
sh.getRange('A1').setBackground('red');
countSMSLogEmails(true);
}
and the "working" code :
function countSMSLogEmails(clearSheet){
var sh = SpreadsheetApp.getActive().getSheetByName('SMS');
var start = Number(PropertiesService.getScriptProperties().getProperty('current thread SMS'));
var CallLogThreads = GmailApp.getUserLabelByName('SMS').getThreads(start,10);
if(CallLogThreads.length==0){
sh.sort(2,false);
sh.getRange('A1').setBackground('#FFC');
var triggers = ScriptApp.getProjectTriggers();
var thisTrigger = PropertiesService.getScriptProperties().getProperty('thisTriggerSMS');
for(var n in triggers){
if(triggers[n].getUniqueId()==thisTrigger){ScriptApp.deleteTrigger(triggers[n])};
}
sh.getRange('A1').setValue('Subject (Log on '+Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "dd-MMM-yy HH:mm")+')');
return;
} else {
PropertiesService.getScriptProperties().setProperty('current thread SMS',start+CallLogThreads.length);
}
var data = [];
for(var n=0;n<CallLogThreads.length;n++){
var thread = CallLogThreads[n];
Logger.log('thread message count = '+thread.getMessageCount());
var msg = thread.getMessages();
var msgData = [];
for(var m in msg){
var msgDate = msg[m].getDate();
var msgSubject = msg[m].getSubject();
var msgBody = msg[m].getBody().replace(/[\n\r]/g,' ').replace(/'/g,"'").replace(/ /g,"!").replace(/&/g,"&").replace(/"/g,'"')
.replace(/>/g,'>').replace(/</g,'<').replace(/<br \/>/g,'\n').replace(/<br>/g,'\n');
msgData.push([msgSubject,msgDate,msgBody]);
}
data.push(msgData);
}
var dataTotal = [];
if (clearSheet==true) {
dataTotal.push(['subject', 'date', 'message']);
}
for(var n in data){
dataTotal = dataTotal.concat(data[n]);
};
Logger.log(JSON.stringify(dataTotal));
if (clearSheet==true) {
sh.clearContents();
sh.getRange(1,1,dataTotal.length,dataTotal[0].length).setValues(dataTotal);
}else{
sh.getRange(sh.getLastRow()+1,1,dataTotal.length,dataTotal[0].length).setValues(dataTotal);
}
}

easeljs cannot dispatch event

I want to dispatch my event,but it doesn't work. this is my code and I've deleted some irrelevant parts .
(function(window){
function HeroSelectView(){
this.initialize();
}
createjs.EventDispatcher.initialize(HeroSelectView.prototype);
HeroSelectView.prototype = new createjs.Container();
var selectedName;
HeroSelectView.prototype.Container_initialize=HeroSelectView.prototype.initialize;
HeroSelectView.prototype.initialize=function(){
this.Container_initialize();
this.initView();
}
HeroSelectView.prototype.initView = function(){
for (var i = 0; i < heroArray.length; i++) {
heroArray[i].x=100+40*i;
heroArray[i].y=200;
this.addChild(heroArray[i]);
heroArray[i].addEventListener("click",onSelectHero);
};
}
function onSelectHero(event){
selectedName=event.target.name;
var myevent = {
type: "selectedEvent",
param: selectedName
};
//var myevent=new createjs.Event("selectedEvent"); //createjs 0.7 doesnot work either.
this.dispatchEvent(myevent);
}
window.HeroSelectView=HeroSelectView;
}(window))
in the onSelectedHero, at first I tried it with createjs-0.61. you can see the "myevent" .But there is an error " TypeError: Argument 1 of EventTarget.dispatchEvent is not an object.". Then I tried it with version 0.7, but still got the same error. How can I fix this?
Thanks

How can i force website to stay in frame?

I'm using Firefox + searchbastard addon to do a multi-search on shopping search engines.The pages are part of a frame. This works just fine for all sites I tried so far except for shopmania.com.
If I use noscript to forbid scripts from the shopmania domain name then everything stays in place but the part of the website elements become nonresponsive. I know there is an option in Firefox to force links that open in a new window to open in a new tab. Is there something similar to prevent websites from popping out of frame? Maybe a Firefox addon that blocks these requests?
Or at least can someone please tell me what is causing only this website to act like this?
EDIT: What tool can i use to pause firefox OR javascript and stepthrough code like in c++ ? I tried a javascript debugger and firebug. They don't help but i'm probably not using them right..
EDIT2: I tried this greasemonkey script : https://userscripts.org/scripts/show/92424. It does not work so i guess it isn't because of 'target' attribute
This is wrong. I'm guessing you're using a plugin to capture and override the output some site gives you. I'm pretty sure this violates their ToS and it's not a very nice thing to do in general.
JavaScript is not designed to allow this kind of meddling. It's patchy at best.
If you want to use the data from a website, to aggregate or display in some manner, use their public API. If they don't have a public API they probably don't want you to use their service in such a manner.
The solution : I took the script from Stop execution of Javascript function (client side) or tweak it and modified it to search for the tag that has in it top.location = location and then appended a new script with the if (top != self) {top.location = location;} line commented . Being a js total newbie i don't know if it's the most elegant choice but it soves the prob. Special thanks to Tim Fountain.
I will leave this open just in case someone else will suggest a better solution, for my and others's education. Again thanks for the help.
Below is the code:
// ==UserScript==
// #name _Replace evil Javascript
// #run-at document-start
// ==/UserScript==
/****** New "init" function that we will use
instead of the old, bad "init" function.
*/
function init () {
/* //changing stuff around here
var newParagraph = document.createElement ('p');
newParagraph.textContent = "I was added by the new, good init() function!";
document.body.appendChild (newParagraph); */
<!--//--><![CDATA[//><!--
document.getElementsByTagName("html")[0].className+=" js "+(navigator.userAgent.toLowerCase().indexOf("webkit")>=0?"webkit":navigator.userAgent.toLowerCase().indexOf("opera")>=0?"opera":"");
for(i in css3_tags="abbr|header|footer".split("|")){document.createElement(css3_tags[i]);}
var PATH = "http://www.shopmania.com";
var PATH_STATIC = "http://im4.shopmania.org";
var PATH_SELF = "http://www.shopmania.com/";
var RETURN = "http%3A%2F%2Fwww.shopmania.com%2F";
var DOMAIN_BASE = "shopmania.com";
var SUBDOMAINS_FORCE_FILES_JS = "aff.remote,biz.remote,my.remote,cp.remote,cp.register_quick,cp.account_details,partner.remote,site.recommend,site.remote,site.feedback,site.report_problem,site.report,site.cropper";
var URL_REWRITE_MAPPING_JS = "cmd,section,do,option|feed,mode,option|forgot,section|info,page|login,section|logout,section|new_password,section,code|settings,section|shopping,param_main,param_sec|site,store_str_key|register,section|unsubscribe,section|agentie,store_str_key,id|brand,manuf_str_key|brands,letter|build,type,param_main,param_sec|compare,online|confirm,section|edit,section|deal,deal|dictionary,online|home,section|link_accounts,section|profile,user|reactivate,section|searches,letter|signup,section|rs_agent,store_str_key|rs_list,param_main,param_sec|rs_view,ad|agents,state|complex_list,param_main|complex_view,complex|list,cat|ad,a|map,option|my_ads,section|my_alerts,section";
var SVR_SITE_ID = "us";
var CONTEXT = "c5b27de70340c97a94092a43bd34b2b8";
var link_close = "Close";
var txt_loading = "Loading...";
var form_is_submitted = 0;
var search_is_focused = 0;
// Overlay object
var OL;
var DB;
var iframe_cnt = "";
// Facebook post to user's Wall action
var FACEBOOK_WALL_FEED_SIGNUP = "";
var SITENAME = "ShopMania";
//if (top != self) {top.location = location;} // SIT!
var comps = new Array(); comps['all'] = 0;var comps_cat_titles = new Array(); var views = new Array(); views['auto'] = 0; views['prod'] = 0; views['realestate'] = 0; views['classifieds'] = 0; views['all'] = 0; var search = new Array(); search['all'] = 0; search['prod'] = 0;
var favs = new Array(); favs['all'] = 0; favs['prod'] = 0; favs['store'] = 0; favs['manuf'] = 0; favs['other'] = 0; favs['realestate'] = 0; favs['auto'] = 0;
function addCss(c){var b=document.getElementsByTagName("head")[0];var a=document.createElement("style");a.setAttribute("type","text/css");if(a.styleSheet){a.styleSheet.cssText=c}else{a.appendChild(document.createTextNode(c))}b.appendChild(a)};
addCss(".lzl {visibility: hidden;}");
var RecaptchaOptions = { theme : 'clean' };
//--><!]]>
}
/*--- Check for bad scripts to intercept and specify any actions to take.
*/
checkForBadJavascripts ( [
[false, /top.location = location/, function () {addJS_Node (init);} ]
] );
function checkForBadJavascripts (controlArray) {
/*--- Note that this is a self-initializing function. The controlArray
parameter is only active for the FIRST call. After that, it is an
event listener.
The control array row is defines like so:
[bSearchSrcAttr, identifyingRegex, callbackFunction]
Where:
bSearchSrcAttr True to search the SRC attribute of a script tag
false to search the TEXT content of a script tag.
identifyingRegex A valid regular expression that should be unique
to that particular script tag.
callbackFunction An optional function to execute when the script is
found. Use null if not needed.
*/
if ( ! controlArray.length) return null;
checkForBadJavascripts = function (zEvent) {
for (var J = controlArray.length - 1; J >= 0; --J) {
var bSearchSrcAttr = controlArray[J][0];
var identifyingRegex = controlArray[J][1];
if (bSearchSrcAttr) {
if (identifyingRegex.test (zEvent.target.src) ) {
stopBadJavascript (J);
return false;
}
}
else {
if (identifyingRegex.test (zEvent.target.textContent) ) {
stopBadJavascript (J);
return false;
}
}
}
function stopBadJavascript (controlIndex) {
zEvent.stopPropagation ();
zEvent.preventDefault ();
var callbackFunction = controlArray[J][2];
if (typeof callbackFunction == "function")
callbackFunction ();
//--- Remove the node just to clear clutter from Firebug inspection.
zEvent.target.parentNode.removeChild (zEvent.target);
//--- Script is intercepted, remove it from the list.
controlArray.splice (J, 1);
if ( ! controlArray.length) {
//--- All done, remove the listener.
window.removeEventListener (
'beforescriptexecute', checkForBadJavascripts, true
);
}
}
}
/*--- Use the "beforescriptexecute" event to monitor scipts as they are loaded.
See https://developer.mozilla.org/en/DOM/element.onbeforescriptexecute
Note that it does not work on acripts that are dynamically created.
*/
window.addEventListener ('beforescriptexecute', checkForBadJavascripts, true);
return checkForBadJavascripts;
}
function addJS_Node (text, s_URL, funcToRun) {
var D = document;
var scriptNode = D.createElement ('script');
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
//--- Don't error check here. if DOM not available, should throw error.
targ.appendChild (scriptNode);
}
there are some escaping issues with the cdata part in the code.So SO does not allow me to post the code.
EDIT: fixed

How to Delete Facebook Messages via Facebook API?

Is there a way to retrieve all Facebook Message ids with the read mailbox permission and then delete them all one by one? Everyone is crying about how it's difficult to delete your chat/message history. I wondered if there was an easy way to write an app to do this.
Facebook API - Message
Normally you would issue an HTTP DELETE call to https://graph.facebook.com/messageID?access_token=... But it appears that this is an API call that either require special whitelisting from Facebook or isn't currently supported because it does not work right now and returns "Unsupported delete request."
Install https://chrome.google.com/webstore/detail/jquerify/gbmifchmngifmadobkcpijhhldeeelkc
Open the facebook using
https://mbasic.facebook.com/messages/?_rdr
Enable jQuery using jQueryify extension you installed.
Then go to your chrome developer tools> sources > snippet and create a new snippet and paste the following code and run it.
// Code snippet for facebook messages removing:
var WHITELISTED_USERS_X = [];
function removeElement(elementId) {
// Removes an element from the document
var element = document.getElementById(elementId);
if (element) {
element.parentNode.removeChild(element);
}
}
function addElement(parentId, elementTag, elementId, html) {
// Adds an element to the document
// removeElement
removeElement(elementId);
var p = document.getElementById(parentId);
var newElement = document.createElement(elementTag);
newElement.setAttribute('id', elementId);
newElement.innerHTML = html;
if (p) {
p.appendChild(newElement);
} else {
var body = document.getElementsByTagName("body")[0]
body.appendChild(newElement);
}
}
addElement("body", "div", "123x", "hello World23");
console.log(`getOlderMessagesLink()`);
console.log(getOlderMessagesLink());
var aLinks = document.querySelectorAll('h3 a'), i;
for (i = 0; i < aLinks.length; ++i) {
let currentLink = aLinks[i];
currentLink.style.color = currentLink.style.color == "black" ? "red" : "green";
$.get( currentLink.href, function( data ) {
getPayload1(currentLink.href).then(payLoad=>{
let abLink = currentLink.href;
let deleteApiLink = abLink.split('?').pop().split('&');
deleteApiLink.splice(1 , 0, `tids=${deleteApiLink[0].split('=').pop()}`)
deleteApiLink = deleteApiLink.join("&").split("#").shift();
const apiLink = `https://mbasic.facebook.com/messages/action_redirect?` + deleteApiLink;
$.post(apiLink, payLoad ).done(function( data ) {
let mydeletehref = findInParsed(data, "a:contains('Delete')");
const username = currentLink.innerText;
const deleteLink = mydeletehref.href;
if(WHITELISTED_USERS_X.indexOf(username) == -1){
// console.log(`${username}: ${deleteLink}`);
insertDeleteLinkInUser(username, deleteLink);
}
});
});
})
}
function getPayload1(link){
return new Promise(resp=>{
$.get(link, function( html1 ) {
let fbDtsg = findInParsed(html1, "input[name='fb_dtsg']");
let jazoest = findInParsed(html1, "input[name='jazoest']");
resp ({
"fb_dtsg": fbDtsg.value,
"jazoest": jazoest.value,
"delete": "Delete"
})
});
})
}
function findInParsed(html, selector){
return $(selector, html).get(0) || $(html).filter(selector).get(0);
}
function getOlderMessagesLink(html = false){
if(html){
return $("#see_older_threads").find("a").get(0).href;
}
let selector = "#see_older_threads";
return $(selector, html).find("a").get(0).href || $(html).filter(selector).find("a").get(0).href;
}
function insertDeleteLinkInUser(username, link){
$("a:contains('" + username + "')").parent().parent().parent().prepend('DELETE ME');
}