Google-sheets – Javascript string() function in Google AdWords

google sheetsgoogle-adwordsgoogle-adwords-scriptsgoogle-apps-scriptjavascript

Is there a simple way to implement the Javascript string() function in the basic Google AdWords interface?

I want to pass some variables returned from a campaign management script to a spreadsheet (for comparing future values against historical values), but setValue() only works for strings.

The string() function does not appear to be available in the Adwords scripting interface.

I want to run something like this:-

  sheet.getRange("B2").setValue(string(A))

Can anyone help?

Best Answer

Coercion in js is amazing and in this case you could simply use like this

sheet.getRange("B2").setValue(A + "")

Simply plus the empty string to your value.

And for something in the similar but reverse way you can use

+myString

Just using as a prefix an unary + operator, this will coerce the string to a number.

Find more about js coercion with a super sensei called Kyle Simpson