AdWordsApp.​DraftSelector

Fetches drafts. Supports filtering and sorting.

Typical usage:

 var draftSelector = AdWordsApp.drafts()
     .withCondition("BaseCampaignId = 123456789")
     .orderBy("DraftName ASC");

 var draftIterator = draftSelector.get();
 while (draftIterator.hasNext()) {
   var draft = draftIterator.next();
 }
Related:

Methods:

MemberTypeDescription
get AdWordsApp.DraftIterator Fetches the requested drafts and returns an iterator.
orderBy AdWordsApp.DraftSelector Specifies the ordering of the resulting entities.
withCondition AdWordsApp.DraftSelector Adds the specified condition to the selector in order to narrow down the results.
withIds AdWordsApp.DraftSelector Restricts this selector to return only drafts with the given draft IDs.
withLimit AdWordsApp.DraftSelector Specifies limit for the selector to use.

get()

Fetches the requested drafts and returns an iterator.

Return values:

TypeDescription
AdWordsApp.DraftIterator Iterator of the requested drafts.

orderBy(orderBy)

Specifies the ordering of the resulting entities. orderBy parameter can have one of the following forms:
  • orderBy("DraftName") - orders results by DraftName, in ascending order.
  • orderBy("BaseCampaignId ASC") - orders results by base campaign id, in ascending order.
  • orderBy("DraftId DESC") - orders results by draft id, in descending order.

See DraftSelector.withCondition(String) for enumeration of columns that can be used.

orderBy() may be called multiple times. Consider the following example:

 selector = selector.orderBy("BaseCampaignId ASC").orderBy("DraftName");

The results will be ordered by BaseCampaignId in ascending order. Results with equal BaseCampaignId values will be ordered by DraftName in ascending order.

Arguments:

NameTypeDescription
orderBy String Ordering to apply.

Return values:

TypeDescription
AdWordsApp.DraftSelector The selector with ordering applied.

withCondition(condition)

Adds the specified condition to the selector in order to narrow down the results.

Multiple conditions may be added to the same selector:

 selector = selector
     .withCondition("BaseCampaignId = 123456789")
     .withCondition("DraftStatus = DRAFTED");
All specified conditions are AND-ed together. The above example will retrieve drafts with base campaign id 123456789 and status DRAFTED.

The parameter to be passed into this method must be of the following form:

 "COLUMN_NAME OPERATOR VALUE"

Operators

The operator that can be used in a condition depends on the type of column.
  • For Long columns (e.g. BaseCampaignId):
    <  <=  >  >=  =  !=
  • For String columns (e.g. DraftName):
    =  !=  STARTS_WITH  STARTS_WITH_IGNORE_CASE
     CONTAINS  CONTAINS_IGNORE_CASE  DOES_NOT_CONTAIN  DOES_NOT_CONTAIN_IGNORE_CASE
  • For Enumeration columns (ones that can only take one value from a predefined list, such as DraftStatus) and Boolean columns:
     =  !=  IN []  NOT_IN []
Conditions using IN and NOT_IN operators look as follows:
 withCondition("ColumnName IN [Value1, Value2]")
Operators are case-sensitive: starts_with won't work.

Columns

All column names are case-sensitive, and so are all values of enumerated columns (such as DraftStatus).

Column Type Example
DraftName String withCondition("DraftName CONTAINS 'draft_'")
DraftStatus Enumeration: DRAFTED, APPLIED, APPLYING, REMOVED, UNABLE_TO_APPLY withCondition("DraftStatus = DRAFTED")
BaseCampaignId Long withCondition("BaseCampaignId = 123456789")
DraftCampaignId Long withCondition("DraftCampaignId = 123456789")
DraftId Long withCondition("DraftId = 123456789")
HasRunningExperiment Boolean withCondition("HasRunningExperiment = true")

Arguments:

NameTypeDescription
condition String Condition to add to the selector.

Return values:

TypeDescription
AdWordsApp.DraftSelector The selector with the condition applied.

withIds(ids)

Restricts this selector to return only drafts with the given draft IDs.

All drafts are uniquely identified by the combination of their base campaign ID and draft ID. The IDs for this selector are thus represented as two-element arrays, with the first element being the base campaign ID and the second being the draft ID:

 var draftIds = [
   [12345, 987987],
   [23456, 876876],
   [34567, 765765],
 ];
 selector = selector.withIds(draftIds);

The resulting selector can be further refined by applying additional conditions to it. The ID-based condition will then be AND-ed together with all the other conditions, including any other ID-based conditions. So, for instance, the following selector:

 var ids1 = [
   [12345, 987987],
   [23456, 876876],
   [34567, 765765],
 ];
 var ids2 = [
   [34567, 765765],
   [45678, 654654],
   [56789, 543543],
 ];
 AdWordsApp.drafts()
    .withIds(ids1)
    .withIds(ids2);
will only get the draft with ID [34567, 765765], since it would be the only draft that satisfies both ID conditions.

Arguments:

NameTypeDescription
ids long[][] Array of draft IDs.

Return values:

TypeDescription
AdWordsApp.DraftSelector The selector restricted to the given IDs.

withLimit(limit)

Specifies limit for the selector to use. For instance, withLimit(50) returns only the first 50 entities.

Arguments:

NameTypeDescription
limit int How many entities to return.

Return values:

TypeDescription
AdWordsApp.DraftSelector The selector with limit applied.

Send feedback about...

Google Ads scripts
Google Ads scripts
Need help? Visit our support page.