AI-generated Key Takeaways
-
Fetches drafts and provides an iterator for accessing them.
-
Allows filtering drafts using conditions like
BaseCampaignId
orDraftStatus
. -
Supports sorting results by draft name, base campaign, or draft ID, in ascending or descending order.
-
Can be limited to a specific number of results using
withLimit()
. -
Enables selection by draft IDs or Google Ads API resource names.
Typical usage:
var draftSelector = AdsApp.drafts() .withCondition("BaseCampaignId = 123456789") .orderBy("DraftName ASC"); var draftIterator = draftSelector.get(); while (draftIterator.hasNext()) { var draft = draftIterator.next(); }
Methods:
Member | Type | Description |
---|---|---|
get() | AdsApp.DraftIterator |
Fetches the requested drafts and returns an iterator. |
orderBy(orderBy) | AdsApp.DraftSelector |
Specifies the ordering of the resulting entities. |
withCondition(condition) | AdsApp.DraftSelector |
Adds the specified condition to the selector in order to narrow down the results. |
withIds(ids) | AdsApp.DraftSelector |
Restricts this selector to return only drafts with the given draft IDs. |
withLimit(limit) | AdsApp.DraftSelector |
Specifies limit for the selector to use. |
withResourceNames(resourceNames) | 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:
Type | Description |
---|---|
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:
Name | Type | Description |
---|---|---|
orderBy | String |
Ordering to apply. |
Return values:
Type | Description |
---|---|
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");
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) andBoolean
columns:= != IN () NOT IN ()
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:
Name | Type | Description |
---|---|---|
condition | String |
Condition to add to the selector. |
Return values:
Type | Description |
---|---|
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);
['34567',
'765765']
, since it would be the only draft that
satisfies both ID conditions. Arguments:
Name | Type | Description |
---|---|---|
ids | Object[][] |
Array of draft IDs. |
Return values:
Type | Description |
---|---|
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:
Name | Type | Description |
---|---|---|
limit | int |
How many entities to return. |
Return values:
Type | Description |
---|---|
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:
Name | Type | Description |
---|---|---|
resourceNames | String[] |
Array of draft resource names. |
Return values:
Type | Description |
---|---|
AdsApp.DraftSelector |
The selector restricted to the given resource names. |