I'm working with Google Apps Script and I'm trying to retrieve the URL hyperlinked to one word in the text string returned by the GAS function below, but I'm getting the error listed below.
As you can see from my code, I'm a rookie, so any help and 'best practice' is greatly appreciated.
Error Message Returned By GAS IDE
TypeError: Cannot find function getLinkUrl in object HYPERLINK to your “Intro To Google Documents” document. Open your MrBenrudShared folder and create a new blank Google Document. Name it “Your Name: Intro To Google Documents”.. (line 19, file "Code")
GAS Function
function getURLfromHyprlink() {
var body = DocumentApp.getActiveDocument().getBody();
Logger.log(body.getNumChildren());
// table is bode child element #1 of 3.
var rubricTable = body.getChild(1);
Logger.log(rubricTable);
// Find out about row 3 in table
var studentWorkRow = rubricTable.getChild(2);
Logger.log(studentWorkRow);
// Find what is in column2 of hyperlink row
var studentHyperlinkCell = studentWorkRow.getChild(1);
Logger.log(studentHyperlinkCell); //tells me it is a table cell
// Returns text from studentHyperlinkCell
var hyperlinkText = studentHyperlinkCell.asText().getText();
var hyperlinkURL = hyperlinkText.getLinkUrl();
Logger.log(hyperlinkURL);
}
THE STRING RETURNED By The Above Function
HYPERLINK to your “Intro To Google Documents” document.
Open your MrBenrudShared folder and create a new blank Google Document. Name it “Your Name: Intro To Google Documents”.
The URL is only on the word HYPERLINK
, and not on the rest of the string.
The document is here - https://docs.google.com/document/d/18zJMjXWoBNpNzrNuPT-nQ_6Us1IbACfDNXQZJqnj1P4/edit# and you can see the word HYPERLINK in row3 of the table and the hyperlink
Thanks for your help!