36

I am trying to use Trello from a Google Spreadsheet (Google Docs) and am not sure how to import/reference/link the javascript files required to use their library. My only other option is using their REST API directly (fine, but I'd rather use their js helper classes).

This is what Trello needs us to use:

 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <script src="https://api.trello.com/1/client.js?key=substitutewithyourapplicationkey"</script>

How would I import/include these in a Google Apps Script?

1

5 Answers 5

54

Based on the answer here by Cameron Roberts, you can use the eval() function on the appscript UrlFetchApp function.

eval(UrlFetchApp.fetch('http://path.to/external/javascript.js').getContentText());
Sign up to request clarification or add additional context in comments.

1 Comment

This is great. I was able to import moment.js into my Google Apps Script code like this: eval(UrlFetchApp.fetch('cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/…); Then I was able to add a calendar entry like this: //Add the years to the date var result = moment(date).add(numberOfYears, 'years').format("MMMM DD, YYYY"); var event = CalendarApp.getDefaultCalendar().createAllDayEvent(' Deadline to for Whatever', new Date(result), { guests: '[email protected]', sendInvites: 'true' });
8

you actually can . In the script project create another new file and simply just paste the JavaScript library copying from the source and save it then start referencing it from other file. It is that simple.

Or you can create another project with the .js lib and publish it and reference that script from the caller project, I wont do that unless that needs to be shared in multiple projects.

1 Comment

One thing to note, functions in other scripts are as if you concatenate them together. No need to import them or load them.
3

Download them and put them in the script. The rest api is easy to use. Ive used trello rest from appscript.

2 Comments

Thanks. I tried that but I downloaded source from the Trello API site and get the following when running the script (referring to the downloaded code): "ReferenceError: "window" is not defined. (line 3, file "TrelloTools")Dismiss"
Google Apps Script is server side, so there is no window object.
2

You cannot use external javascript libraries this way in Google Apps Script. (You can do so in html files used with the HtmlService. Since so much of Trello is client-side anyway, this may be just what you need.)

In server-side apps script, you should be able to access the library code using the technique from this answer. It doesn't say, but I'd imagine that you would put that eval outside of all functions in your script, to make the objects in the library available to the rest of your code.

1 Comment

any specific examples of this? I haven't been successful yet from a Google Spreadsheet.
0

Yes you can use JavasSript libraries in Google script. Copy all content of the libraries JavaScript and post it in new GS file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.