AdWords script: Exlcude exact keyword in BMM adgroup

Short AdWords script for automatically excluding exact keywords from the exact adgroup to a similar broad campaign.

This script finds adgroups containing exact match keywords based on an identifier in the adgroup name. Consequently, keywords in this are placed in the adgroup which contain broad or BMM keywords.

For example: the exact keyword [white shoes] in the adgroup White shoes (exact) will be placed as a negative exact keyword in the adgroups White shoes (BMM).

/*
  check log output for run details

  sources:
  createnegativekeywords https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_adgroup
  negative keywords https://developers.google.com/adwords/scripts/docs/examples/negative-keywords
*/

// ********* Settings *********
var mBroad = "(BMM)"   // broad adgroup name contains...
var mExact = "(exact)" // exact adgroup name contains...

// Functions, do not change
function main() {
  Logger.log('Run: exclude all ' + mExact + ' keywords in adgroups that contain ' + mBroad);
  exactExclude();
}

function exactExclude() {
  var keyBMM = AdWordsApp.keywords()
    .withCondition("AdGroupName CONTAINS_IGNORE_CASE '" + mExact + "'")
    .orderBy('AveragePosition ASC')
    .forDateRange('TODAY')
    .get();
  
  // for logging
  var changer = 0;
  
  // loops through awql result
  while (keyBMM.hasNext()) {
    var keyword = keyBMM.next();
    var keyText = keyword.getText();
    var keyAdGroup = keyword.getAdGroup();
    var keyAdGroupName = keyword.getAdGroup().getName();
    Logger.log(keyText + ' in adgroup: ' + keyAdGroupName);
    var changer = changer + 1;
    
    // find broad adgroup
    var keyAdGroupNameBroad = keyAdGroupName.replace(mExact, mBroad);
    var adGroupIterator = AdWordsApp.adGroups()
      .withCondition('Name = "' + keyAdGroupNameBroad + '"')
      .get();
    if (adGroupIterator.hasNext()) {
      var adGroup = adGroupIterator.next();
      adGroup.createNegativeKeyword(keyText);
    }
    
    Logger.log('______________');

  }
  Logger.log(changer + 'woorden');
}