I am trying to create a portfolio tracker in google sheets. For that I have written a custom function in App Script. The function is taking two inputs - ticker symbol (tickers) and amount (values). Whenever I try to call the function in excel sheet, it is throwing an error as 'Reference does not exist'
function MyPortfolio(tickers, values)
{
var total = []
var sums = {}
for (i=0;i<tickers.length; i++)
{
var t = tickers[i].toString()
if(t!="Cash")
{
if(t in sums)
{
sums[t]+=Number(values[i])
}
else
{
sums[t]=Number(values[i])
}
}
}
for(var ticker in sums)
{
if(sums[ticker]>0)
{
total.push[ticker, sums[ticker]]
}
}
return total
}
Need help
An empty array is not a valid return value.
Make sure that total is not empty.
If you do not want to return a value, you can return an array with empty values ["",""] .
The issue is resolved. It was a syntax error
.
.
total.push([ticker, sums[ticker]])
.
.
I forgot to put round brackets (...)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.