Google Ads Script SetAmount() function in new experience

117 views
Skip to first unread message

Paul van Putten

unread,
Jul 26, 2022, 6:46:04 AM7/26/22
to Google Ads Scripts Forum
Hi,

today I tried migrating all of our scripts to the new experience. With one of the scripts, I am running in some trouble. I run this piecie of code (which works fine in the 'old' script): 

videoCampaign.getBudget().setAmount([new_budget]);

New budget is the variable that we want to set as new budgets. Examples are: 7.33320406 and 21.13443846. The old script would automatically round these numbers and set the budgets to 7.33 and 21.13. However, with the new experience I get the error message as attached. For some reason, the script does not recognise it as positive numbers. I cannot seem to solve this. How do I fix this? 

Please let me know if you have any further questions

Schermafbeelding 2022-07-26 om 12.42.39.png

Martijn Kraan

unread,
Jul 26, 2022, 9:57:00 AM7/26/22
to Google Ads Scripts Forum
Hi Paul,

Maybe you can round the number to two decimals?

let new_budget = 123.23454;
new_budget = new_budget.toFixed(2);

Or, is the number isn't recognised as a number (but as text instead) try to convert to a number first:

parseFloat("123.456").toFixed(2);

I don't know if this works, but worth a try maybe?
Good luck!

Martijn

Google Ads Scripts Forum Advisor

unread,
Jul 26, 2022, 12:27:35 PM7/26/22
to adwords...@googlegroups.com
Hi Paul,

Thanks for reaching out. Can you please provide us with the CID and script name so that we can take a closer look at this issue?

Thanks,

Google Logo
Matt
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2d1VqH:ref

Paul van Putten

unread,
Jul 27, 2022, 3:03:38 AM7/27/22
to Google Ads Scripts Forum on behalf of adsscripts
Hi,

I managed to fix it. It indeed was the case that the script did not recognise the [new_budget] in this function (videoCampaign.getBudget().setAmount([new_budget]);) as a list of numbers, but as text. I fixed it by adding a '+' sign before the new_budget. I read this on the internet somewhere and it worked. So now it looks like this:

videoCampaign.getBudget().setAmount([+new_budget]);

Thanks for the responses.

Kind regards,

Coolblue  
Paul van Putten
Analist Banner & Video
Twitter LinkedIn
Weena 664, 3012 CN Rotterdam
Coolblue.nl Werkenbijcoolblue.nl


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/tOQrKPrKHFE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/lfH6f000000000000000000000000000000000000000000000RFMZ1T00xXIkJQjZQnyvSMb6MQexjQ%40sfdc.net.
Reply all
Reply to author
Forward
0 new messages