AdWords
1.9K members online now
1.9K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Scipt to edit shared budget on certain days of the week

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi guys,

I have this script below from Jon Gritton (credit to Jon) which is supposed to automate my shared budget "SharedBudget1" to be £500 for Mon/Tue/Wed and £300 for Thur/Fri/Sat/Sun. Something however isn't going right. I'm sure from this you may notice that I am a scripting rookie. Can anybody solve this?

// script to change budget by day of week
// Jon Gritton 2016

// user vars
var BUDG_NAME = "SharedBudget1";
var B_MON = 500;
var B_TUE = 500;
var B_WED = 500;
var B_THU = 300;
var B_FRI = 300;
var B_SAT = 300;
var B_SUN = 300;

function main() {
  setBudget(getBudgetToday());
}

function getBudgetToday() {
  var budgArray = [B_SUN,B_MON,B_TUE,B_WED,B_THU,B_FRI,B_SAT];
  var d = new Date(Utilities.formatDate(new Date(), AdWordsApp.currentAccount().getTimeZone(), "MMM dd,yyyy HH:mm:ss"));
  var today = d.getDay();
  return budgArray[today];
}

function setBudget(budgetToday) {
  Logger.log("Budget for today is: " + budgetToday);
  var budgetIter = AdWordsApp.budgets()
    .withCondition("BudgetName = '" + BUDG_NAME + "'")
    .get()
  while (budgetIter.hasNext()) {
    var thisBudget = budgetIterator.next();
    thisBudget.setAmount(budgetToday);
  }
}

Scipt to edit shared budget on certain days of the week

Explorer ✭ ✭ ✭
# 2
Explorer ✭ ✭ ✭

Hello @Mike L

 

What is exactly your problem? The script returns an error, works fine but doesnt work as you wish or it doesn't start at all? 

 

Don't forget to program the script daily in order to run it automatically every day.

 

Let us know.

 

Regards,

 

Hana

Scipt to edit shared budget on certain days of the week

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hello @Hana K

Thanks for the reply.

The logs read:

Budget for today is: 500
ReferenceError: "budgetIterator" is not defined. (line 31)

 

Scipt to edit shared budget on certain days of the week

Explorer ✭ ✭ ✭
# 4
Explorer ✭ ✭ ✭

Hello,

 

change this line:

var thisBudget = budgetIterator.next();

 

to this line:

var thisBudget = budgetIter.next();

 

Regards,

 

Hana

Re: Scipt to edit shared budget on certain days of the week

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
Thanks Hana that worked perfectly