AdsApp.​DraftSelector

Stay organized with collections Save and categorize content based on your preferences.
Fetches drafts. Supports filtering and sorting.

Typical usage:

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

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

Methods:

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

get()

Fetches the requested drafts and returns an iterator.

Return values:

TypeDescription
AdsApp.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("campaign_draft.name") - orders results by draft name, in ascending order.
  • orderBy("campaign_draft.base_campaign ASC") - orders results by base campaign resource name, in ascending order.
  • orderBy("campaign_draft.draft_id 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("campaign_draft.base_campaign ASC")
     .orderBy("campaign_draft.name");

The results will be ordered by campaign_draft.base_campaign in ascending order. Results with equal campaign_draft.base_campaign values will be ordered by campaign_draft.name in ascending order.

Arguments:

NameTypeDescription
orderBy String Ordering to apply.

Return values:

TypeDescription
AdsApp.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. campaign_draft.draft_id):
    <  <=  >  >=  =  !=
  • For String columns (e.g. campaign_draft.name):
    =  !=  (NOT) (LIKE | CONTAINS | REGEXP_MATCH)
  • For Enumeration columns (ones that can only take one value from a predefined list, such as campaign_draft.status) and Boolean columns:
     =  !=  IN () NOT IN ()
Conditions using IN and NOT IN operators look as follows:
 withCondition("ColumnName IN (Value1, Value2)")

Columns

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

Column Type Example
campaign_draft.name String withCondition("campaign_draft.name CONTAINS 'draft_'")
campaign_draft.status Enumeration: DRAFTED, APPLIED, APPLYING, REMOVED, UNABLE_TO_APPLY withCondition("campaign_draft.status = DRAFTED")
campaign_draft.base_campaign String withCondition("campaign_draft.base_campaign = 'customers/1234567890/campaigns/123'"). The value is a campaign resource name.
campaign_draft.draft_id Long withCondition("campaign_draft.draft_id = 123456789")
campaign_draft.has_experiment_running Boolean withCondition("campaign_draft.has_experiment_running = true")

Arguments:

NameTypeDescription
condition String Condition to add to the selector.

Return values:

TypeDescription
AdsApp.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'],
 ];
 AdsApp.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 Object[][] Array of draft IDs.

Return values:

TypeDescription
AdsApp.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
AdsApp.DraftSelector The selector with limit applied.

withResourceNames(resourceNames)

Restricts this selector to return only drafts with the given Google Ads API resource names.
 const draftResourceNames = [
   'customers/1234567890/campaignDrafts/111~222',
   'customers/1234567890/campaignDrafts/111~333',
   'customers/1234567890/campaignDrafts/444~555',
 ];
 selector = selector.withResourceNames(draftResourceNames);

The resulting selector can be further refined by applying additional conditions to it. The resource name condition will then be AND-ed together with all the other conditions.

The selector can only support up to 10,000 resource names. If more than 10,000 resource names are specified, the corresponding get() call will fail with a runtime error.

Arguments:

NameTypeDescription
resourceNames String[] Array of draft resource names.

Return values:

TypeDescription
AdsApp.DraftSelector The selector restricted to the given resource names.