Monday, 22 September 2014

Inserting a Link To A Google Drive File in a Google Spreadsheet

It seems Google are changing how you use the Google Drive File Chooser which always looks a bit goofy if you are using it in a spreadsheet because of poor design.

I had a go to see if I can resize the dialog at all and I don't think so. Here's my version of their code which demonstrates how you can wire it to insert a link to a Google Drive file.

There's an example file here: Drive Dialog example. Simply go to the File > Make a copy menu to see the code using Tools > Script Editor menu.

Thursday, 18 September 2014

Where Do Good Ideas Come From?

Many people think ideas happen in a flash, a moment of inspiration, that eureka moment. They also believe that it's often "other people" that have ideas, either a boss or lone genius hunting down those illusive light bulbs.

The funny thing is, that the reality is, ideas can be slow things, taking time to come into being and most often they happen in discussion or collaboration. From what I've seen, the best ideas don't come from senior management, or from a sole genius but from people working together, people actually doing stuff in the real world. Many of these "good ideas" can be almost accidental.

My role at the university has been to both introduce people to the Google Apps suite, both evangelising them and working with people to help them realise their ideas.

Here's a story of an "accidental idea" that I think is good and is a great example of what I call "people actually stuff" and collaboration and discussion.

Someone in Facilities in Harry Fairhurst, let's call him Andrew, was talking to someone in the Communications Team, we can call her Jess because that's her name too. They came to me, Tom, and asked, "Can we have a spreadsheet to make the recording of seat availability in Harry Fairhurst easier?"

I didn't know that this information was collected. I showed them how to add drop downs and colours to a Google Spreadsheet. Job done.

I then discovered that someone actually regularly patrols the building and carries an android tablet. I had the thought that instead of it being a spreadsheet, which was OK but not ideal, it could be an app, better designed for updating on the move. It took me about half an hour to make an app that did that for them, updating the same spreadsheet, using Apps Script. Apps Script is a coding language based on JavaScript built into Google Spreadsheets, Sites and Docs and it's a fantastic tool for people who want to quickly make their ideas happen.

The story doesn't end here. Previously, I'd shared an office with Aimee, who'd discovered that with a little HTML hacking, we could show some Google data on the York website. And so the Jess added the seat availability page to our web site as a trial service. An accidental feature of the technology means that this chart is updated every 5 minutes, rather than twice a day like the web site.

And the story goes on. By now, only days after "launching" a trial service the Communications Team were already receiving positive feedback from students.

Next, Jess and Steve, seeing that the data could be displayed on the web site, asked if it could also be displayed on the big screens around Harry Fairhust. We found that the original spreadsheet looked a "bit lost" on the big screens, so wrote some code to "push" the data from the main spreadsheet to another sheet formatted with bigger fonts etc (shown below).

function copy_sheet(){
  //Simply makes a copy of the main sheet
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = ss.getSheetByName("Seating availability")
  var range = sheet.getDataRange()
  var a1 = range.getA1Notation()
  var values = range.getValues()
  var destination_spreadsheet = SpreadsheetApp.openById('SHEET_ID')
  var destination_sheet = destination_spreadsheet.getSheetByName("Big Screen")
  var destination_range = destination_sheet.getRange(a1)
  destination_range.setValues( values )

The trial Seating Availability service came into being after chance questions and discussions. It took little to no time to put together. It uses Google Spreadsheets, an app, an android tablet, a widget embedded in a web page and our big screens. It involved at least four or five people.

The is already hugely popular for all sorts of reasons. I heard from disability services that students with problems with anxiety love being able to avoid "nearly full" study spaces.

We will soon be adding extra areas and improving it based on feedback.

If you're still wondering where good ideas come from...

Tuesday, 2 September 2014

Showing When An Appointment Slot is FULL using Google Forms and Apps Script

I'm sorry this isn't a finished solution you can just copy and paste. It's more of an example, sharing THAT this can easily be done which may help you figure out how to do it your case.

Lots of people at the University of York are using Google Forms to allow people to sign up to events. They use forms rather than Appointment Slots because they want to work with the data to generate registers for the people running the events.

But often these events have a capacity, that is, once 20 people have signed up to them, they're full.

There isn't much you can do with Google Forms to "live lookup" data and change form items if they're full, so we have developed workarounds to mimic this behaviour.

Firstly, having created our Form in the regular way, we create an extra sheet that keeps a track of how many people have have signed up, like this...

The count column has a formula in it like this...

=COUNTIF('Form responses 1'!G:G,B2)

...and the limit is a number we entered of how many places that slot has.

Secondly, we need to create a couple of functions that get fired when someone signs up to a session, like this...

function find_limits(rangeA1, their_choice){ //the values for the range and choice parsed in the main function
// the range is where you want to look in Group Totals var ss = SpreadsheetApp.getActiveSpreadsheet() var sheet = ss.getSheetByName("Group Totals") var range = sheet.getRange(rangeA1) var values = range.getValues() //get the count and limit values for the question's range for the user's choice for ( v in values){ var row = values[v] if (row[0] == their_choice){ return [row[1], row[2]] //the first value (row[0]) is their choice
// the second value (row[1]) is the count 
// the third value (row[2]) is the limit } } } function test_find_limits(){ Logger.log( find_limits("B3:E23", "11:45-12:00")) }


function check_availability(item_id, count, limit, their_choice){ var ss = SpreadsheetApp.getActiveSpreadsheet() var sheet = ss.getSheetByName("Group Totals") var form_id = "YOUR_FORM_ID_HERE" //the form ID is from the url. var form = FormApp.openById(form_id) var items = form.getItems() var item = form.getItemById(item_id).asListItem() var choices = item.getChoices() //pulls out the multiple choice question choices.  
//Can't pull out one particular choice so pulls them all out and iterates var choices_list = [ ] for (c in choices){ var choice = choices[c] if (choice.getValue() == their_choice){ if (count >= limit){ //It's up to the limit! choices_list.push(their_choice + " FULL!" ) 
}else{ choices_list.push(choices[c].getValue()) } }else{ choices_list.push(choices[c].getValue() ) } } item.setChoiceValues(choices_list) }

So, basically, when someone books an appointment, the script looks in the "Group Totals" sheet, and if the count is equal to the limited number of places, it changes the multiple choice items title to "10:00 - 10:30 FULL!".

What's interesting about this is that although you can't do live changes to the form, this script essentially changes the form items for the next person who uses it.

I did experiment with deleting the multiple choice item, but had a few funny results, so thought it best to just change its name. This can be a good idea anyway, to show to users that slots did exist but now they're gone.

Of course in this case someone can still book a full slot ( it doesn't prevent it) , but this process is, in our case, policed by a human anyway. This method is a way to heavily dissuade people from selecting full course slots.

Hope this helps.