- You want to put a formula using the custom function.
- You want to achieve this using Google Apps Script.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Modification points:
- Unfortunately, the custom function cannot put the formula. I think that this is the specification of Google side. So in your case, it is required to use a workaround.
- As a workaround, I would like to propose to put the formula using the OnEdit event trigger.
- In this case, when
=jiraHyperlinks(reference) is put to a cell, the value of cell is converted to the formula by the OnEdit event trigger.
Sample script:
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 + '")');
}
}
Usage:
- In order to run the above script, after the script is copied and pasted to the script editor and save it, please put the formula of
=jiraHyperlinks("sample") to a cell. By this, =jiraHyperlinks("sample text") is converted to =HYPERLINK("https://jira.fanatics.com/browse/sample", "sample").
Note:
- This is a simple sample script for testing this workaround. The script might be required to be modified for the situation. Please be careful this.
References:
If I misunderstood your question and this was not the direction you want, I apologize.
Edit:
- In this sample script, the formula is directly retrieved from the edited range without using
e.value.
Sample script:
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 + '")');
}
}
jiraHyperLinksfunction above. It prints the text "=HYPERLINK(etc etc)" into the cell. On further research it seems like this is something Google does not allow - I found examples of inserting formulas into other cells, but not converting content into a formula and using the result. - elemjay19jiraHyperlinks()in the script editor, please modify the function name. - Tanaike