Reputation: 1166
I have a google sheet that has a column of values that are Jira ticket names. I want to create a script insertJiraLink
that accepts a cell reference and outputs a hyperlink where the text is the ticket name and the link goes to the actual Jira ticket.
I can create a jira link easy enough. But I cannot figure out how to return a hyperlink with custom text.
// returns a full jira hyperlink
function jiraLinks(reference) {
return "https://jira.fanatics.com/browse/" + reference;
}
// returns text that reads "=HYPERLINK(etc etc)"
function jiraHyperlinks(reference) {
return '=HYPERLINK("https://jira.fanatics.com/browse/'
+ reference
+ '", "'
+ reference
+ '")';
}
Upvotes: 1
Views: 1828
Reputation: 201378
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
=jiraHyperlinks(reference)
is put to a cell, the value of cell is converted to the formula by the OnEdit event trigger.function onEdit(e) {
var value = e.value.split("\"");
if (/^=jiraHyperlinks\(/.test(value[0])) {
var reference = value[1];
e.range.setFormula('=HYPERLINK("https://jira.fanatics.com/browse/' + reference + '", "' + reference + '")');
}
}
=jiraHyperlinks("sample")
to a cell. By this, =jiraHyperlinks("sample text")
is converted to =HYPERLINK("https://jira.fanatics.com/browse/sample", "sample")
.If I misunderstood your question and this was not the direction you want, I apologize.
e.value
.function onEdit(e) {
var range = e.range;
var value = range.getFormula().split("\"");
if (/^=jiraHyperlinks\(/.test(value[0])) {
var reference = value[1];
range.setFormula('=HYPERLINK("https://jira.fanatics.com/browse/' + reference + '", "' + reference + '")');
}
}
Upvotes: 1