'Modifying formula to work in appsscripts code

I am looking for some help on modifying an equation so that it works inside appsscript code.

Formula in GoogleSheets: =IF(HOME!T2:T<>"",TRANSPOSE(IMPORTXML(LEFT(HOME!T2:T,FIND("#",SUBSTITUTE(HOME!T2:T,"/","#",4))-1),"//strong[@data-e2e='video-views']")),"")

Line in AppsScript: cell.setFormula("=IF(HOME!T2:T<>'',TRANSPOSE(IMPORTXML(LEFT(HOME!T2:T,FIND("#",SUBSTITUTE(HOME!T2:T,'/','#',4))-1),'//strong[@data-e2e='video-views']')),'')");

Resulting error: error in appsscript

Appreciate any help I can get with this!



Solution 1:[1]

Sorry, maybe my brain was just not functioning correctly. I have escaped the quotation marks within the String and hopefully it should work now:

cell.setFormula("=IF(HOME!T2:T<>\"\",TRANSPOSE(IMPORTXML(LEFT(HOME!T2:T,FIND(\"#\",SUBSTITUTE(HOME!T2:T,\"/\",\"#\",4))-1),\"//strong[@data-e2e='video-views']\")),\"\")");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dan