Update Anchor from function - google-apps-script

In my process, I have a page that the user can select various items from a Listbox. These values are a Cell in a spreadsheet. A different column on that spreadsheet contains the URL of the spreadsheet. So after the user selects the value from listbox, the cell containing the URL is stored to a variable using a createServerClickHandler. What I can do already, is pass that URL back to a Textbox on the main page displaying the URL. What I'd like to do is have an Anchor appear on the main page so that, the user can click on it to open the spreadsheet that is the currently selected on in the Listbox.
var urlText = 'Click here to see selected spreadsheet';
var urlLink = bldrapp.createAnchor(urlText, **urlURL**).setId('spreadsheetURL').setVisible(true);
From my function(e)
app.getElementById('infoURL').setText(**docToProcessURL**).setVisible(true);
The 'infoURL' is my Textbox on the main page. Is it possible to pass that value up to the 'urlURL' in the anchor?
Thank you,

Yes, you can do it like this:
app.getElementById('spreadsheetURL').setHref(docToProcessURL);

Related

Need to create dynamic hyperlink or change cell remotely

I've created a google spreadsheet. It has a master sheet, and I made a query function to pull data for my team.
My team has to update the column that has a comment section. But pulled data cannot be changed.
Now I need either of solutions:
1. Change the original cell in the master sheet remotely
2. Have a dynamic hyperlink to the cell they need to update
Here what I would want for the option №2 in my google spreadsheet - excel example I found on the internet
Solution
I believe this is what you were looking for (if not please clarify a bit more your question): you want to create a dropdown list that depending on the name on it the link next to it will change accordingly to direct you to the specific cell of that person in the other sheet.
If that is the case here is the simplified piece of code that will achieve this with self explanatory comments:
function onEdit() {
// Get the two sheets
var ss1 = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var ss2 = SpreadsheetApp.getActive().getSheetByName('Sheet2');
// Create an array for the dropdown list
var names = ['Ramon', 'Jose', 'Pepito'];
// Build the dropdown data validation
var dropdown = SpreadsheetApp.newDataValidation().requireValueInList(names).build();
// Set the dropdown to your desired ccell and attach the validation to that cell
var dropdownCell = ss1.getRange('A1');
dropdownCell.setDataValidation(dropdown);
// For every case of your dropdown (for every name) create an if condition so that the link on the side keeps changing
// accordingly to who is set on the drop down (i.e repeat this step for the rest of the names).
if(dropdownCell.getValue()=='Ramon'){
// Set the vale of B1 to the hyperlink formula (you need to get your linked sheet id and the range or cell you want to link it to.
ss1.getRange("B1").setValue('=hyperlink("#gid='+ss2.getSheetId()+'&range='+ss1.getRange('B112').getA1Notation()+'", "Click to jump to Sheet 2")');
}
}
For achieving this I took use of the formula hyperlink and of the Apps Script tool for creating data validation and setting it to a specific cell. Moreover, the use of onEdit() will allow you to catch instant changes in the dropdown cell.
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)

How to handle Access DataSheetView selection change event..?

I have a Form with Default View Split Form enabled, so it will appear like picture below every time it loaded.
I also enable the page header to appear at the top which has a label to store some value (It will store Diff Amount value). What I want to do is, everytime user click on the datasheet view (and make record selection change or cell change) below the form header, I want to update the value of my label on the form header.
It's easy to change the value, but how to handle the datasheet view record selection, or datasheet view cell selection change.
In Excel, this is very easy to do, we can handled it from Worksheet.SelectionChange event, but how to do this in Access...?
Thanks in advance.
Simply use the form OnCurrent event, which fires whenever a new record becomes Current

Displaying a Google form on sheets

I am creating a form for users to input information on a Google spreadsheet. They will access the spreadsheet and then click on an image that is linked to a script. When the image is clicked, I want a form to appear. Then I want the input from the form to be accessible in the script.
I am able to create a form but the form does not appear on the sheet. Here is the code thus far for the GS script
function startForm() {
var form = FormApp.create('myForm');
var item = form.addCheckboxItem();
item.setTitle('What would you like to do?');
item.setChoices([
item.createChoice('Budget Inquiry'),
item.createChoice('Add Purchase')
]);
var choices = item.getChoices();
// then I can respond to the user's choice
}
I would like this simple form to just appear on the google sheet. Any input would be appreciated.
Instead of creating you own form with script, just go to the insert menu of your spreadsheet and select form. Enter you question and your two choices. Close the form. You will see a form response sheet created in your spreadsheet. Also, a menu item Form will appear on your menu. Then go to the script editor and from the menu select Resources. Select Current Project Triggers and set a new trigger for onFormSubmit. You can then enter a function onFormSubmit to do whatever you want done when the form is submitted getting data from the form response sheet. There is plenty of documentation you can Google.
The way in Google Sheets to display external content other than images and Google Drawings is by creating a dialog or sidebar with the related content embeded.
There is a similar question that includes an answer that shows how to do this:
Single Google Form for multiple Sheets

Add custom Data to Google Sheet once Form is filled

I am using a Goofle form that receives applications from users, once the form is submitted I am using Google form submission trigger to notify. It has some questions like (facebook profile link)
But while sending a notification I don't want those links to be appeared just the same way user enters, instead something like Facebook, twitter (text as hyperlinked.) should appear
I already know about onFormsubmit() function, but not sure how to use, help me out please.
For example:
Cell A2 has user submitted facebook profile link using the form.
I want Column B2 to automatically generated as =hyperlink(A2, "Facebook")
The same thing should happen like A3 to B3 whenever user submits a form.
Ok after a bit of digging and testing, I believe I got a solution for you since you use the "Yet Another Mail Merge" (aka YAMM) add-on. Here it goes:
Firstly make sure your Form is setup properly and linked to a Google Sheet. After all questions have been created, add another column to your sheet, and call it 'Hyperlink' or whatever you please (just remember it for later). We will make use of the form submit trigger in the script editor along with some code.
Here's the code:
function onFormSubmit(e)
{
var r = e.range;
var v = e.namedValues;
var link = v['Link'];
// For testing purposes, this part was apart of my form,
// I'd assume you'd want to change it to something more
// usable in your case. Notice that I refer to the values
// by the name of the question they preside in.
var friendlyName = v['Friendly Name'];
var rngHyper = getCellRngByCol(r, 'Hyperlink');
// See below for the meaning of the boolean
addHyperlink(rngHyper, link, friendlyName, true);
}
// Will only return one cell no matter the range size.
// Perfect for onFormSubmit(e) use case.
function getCellRngByCol(rng, col)
{
var aRng = SpreadsheetApp.getActiveSheet().getDataRange();
var hRng = aRng.offset(0, 0, 1, aRng.getNumColumns()).getValues();
var colIndex = hRng[0].indexOf(col);
return SpreadsheetApp.getActiveSheet().getRange(rng.getRow(), colIndex + 1);
}
// Add some form of hyperlink reference to one particular
// cell, passed as a range object
function addHyperlink(rng, link, name, useFormula)
{
if (useFormula)
{
// If useFormula is TRUE, use Google Sheet HYPERLINK formula,
// only if you are sure all URL's are formated properly,
// and include HTTPS/HTTP/WWW. Also looks more pleasing in Google Sheet.
var formula = '=HYPERLINK("<<URL>>", "<<NAME>>")';
formula = formula.replace('<<URL>>', link).replace('<<NAME>>', name);
rng.setFormula(formula);
}
else
{
// Else use HTML <a> tag with hyperlink referencing, which should transform
// any URL passed as a clickable hyperlink within email. Not very visually
// appealing in Google Sheet.
var value = '<<NAME>>';
value = value.replace('<<URL>>', link).replace('<<NAME>>', name);
rng.setValue(value);
}
}
Then set the trigger, which will probably ask for authorization after saving:
Next, save the script and then put in a test submission through your form to see that the link is created properly, or as desired. Afterwards clear the rows of the spreadsheet (not the header) and remove all responses of the Form itself (not necessary, but keeps things organized for testing purposes).
Now, install the YAMM add-on. It should then add a new column at the end of your sheet called 'Merge satus'. Before setting up the email notification on submit, we need to create your email template. Open up GMAIL, create an email with the desired fields and layout and save it as a draft. Here's what I did as an example:
I'm sure you're familiar with how this add-on, works so I shouldn't need to explain too much here.
After the draft has been created and saved, go back to the Google Sheet attached to the Form. Go to Add-ons > YAMM > Configure form submission notifications. I chose the 'Notify one or more addresses of all responses' option which are tied to the 'To:' emails preset in the draft. Select your draft from the drop down, fill in sender name if needed, AND (very important!!) check the 'Wait until a specific column is filled before sending the email' check box. Make sure to select the Hyperlink column (or whatever you chose to name it earlier). Here's my setup for reference:
Save it, test it, and ta-da. This simple formatting for hyperlinks has been resolved! :D

how to make dynamic google form by modifying stored form

I'm trying to create a dynamic form based on a stored form.
The code I wrote is not working.
When the users that got the form to fill in, run it,
it should first modify all the texts and replace the word kkkk with a keyword determined according to the last submit.
If that cannot be done, then I would like the form when submitted to be modified for the next time it is opened. Is that possible.
I understand that code in onOpen() and onSubmit() do not have permissions to modify the form. So I made my own modifyForm() function, and added a trigger to From-Form On-Submit. Still not working.
The code DID work when I had the trigger set to From-Form On-Open, but only when I closed the form and re-opened it for editing. - That behavior is documented. So, again, I'm looking for a way that each time the form is run, or each time the form is submitted, it is dynamically modified.
function onModify(){
var form = FormApp.getActiveForm();
var imgURL = "http://whatever.com/someimg.jpg";
var img = UrlFetchApp.fetch(imgURL);
// i first check that there is an image item in the current form and then
var imgItem = form.getItems(FormApp.ItemType.IMAGE)[0];
imgItem.setImage(img);
var keyword = "aaaa"; //getKeyword(); // some text returning function
var items = form.getItems();
for (i=0; i<items.length; i++){
var title = items[i].getTitle();
title = title.replace("kkkk", keyword);
items[i].setTitle(title);
}
return form;
}
Thanks for any help you can give!!
Not possible on google forms alone.
So my solution was to create four stored copies of the form replacing "kkkk" keyword in advance, all going to the same spreadsheet but to different sheets, and on a separate website I decide in python which copy of the form to present to the user by redirecting.
I have to store some sort of identification so that the user does not get two types of the form (but that's a separate issue).