AdsApp.AdOperation
Stay organized with collections
Save and categorize content based on your preferences.
An operation representing creation of a new ad. Calling any
method
(
getErrors,
getResult, or
isSuccessful)
will cause the operation to execute and create the ad. To
make the script more efficient, it's recommended that you store the
operations in an array and only call these methods once you've constructed
all the operations you want.
For instance, this is how you would assign a label to newly created ads in
an efficient manner:
// For the purpose of this example, suppose that the fetchAdText() function
// fetches text ad data from your data source of choice, so that
// adsToCreate is an array where each element is an object describing an ad.
var adgroup = AdsApp.adGroups().get().next();
var adsToCreate = fetchAdText();
var adOps = [];
for (var i = 0; i < adsToCreate.length; i++) {
adOps.push(
adGroup.newAd().expandedTextAdBuilder()
.withHeadlinePart1(adsToCreate[i].headlinePart1)
.withHeadlinePart2(adsToCreate[i].headlinePart2)
.withDescription(adsToCreate[i].description)
.withPath1(adsToCreate[i].path1)
.withPath2(adsToCreate[i].path2)
.withFinalUrl(adsToCreate[i].finalUrl)
.build());
}
for (var i = 0; i < adOps.length; i++) {
if (adOps[i].isSuccessful()) {
adOps[i].getResult().applyLabel('myLabel');
} else {
Logger.log('Errors from Ad [' + adsToCreate[i].headline + ']: '
+ adOps[i].getErrors());
}
}
Methods:
Member | Type | Description |
getErrors() |
String[] |
Returns an empty array if the operation was successful, otherwise returns
the list of errors encountered when trying to create the Ad. |
getResult() |
AdsApp.Ad |
Returns the newly created Ad, or null if
the operation was unsuccessful. |
isSuccessful() |
boolean |
Returns true if the operation was successful. |
getErrors()
Returns an empty array if the operation was successful, otherwise returns
the list of errors encountered when trying to create the Ad.
Return values:
Type | Description |
String[] |
The errors that occurred during the AdOperation . |
getResult()
Returns the newly created Ad, or
null
if
the operation was unsuccessful.
Return values:
Type | Description |
AdsApp.Ad |
The Ad
created by the AdOperation. |
isSuccessful()
Returns
true
if the operation was successful.
Return values:
Type | Description |
boolean |
true if the operation was successful. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-25 UTC.
[null,null,["Last updated 2025-08-25 UTC."],[[["\u003cp\u003e\u003ccode\u003eAdOperation\u003c/code\u003e represents the creation of a new ad, executing upon calling \u003ccode\u003egetErrors\u003c/code\u003e, \u003ccode\u003egetResult\u003c/code\u003e, or \u003ccode\u003eisSuccessful\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor efficiency, store multiple \u003ccode\u003eAdOperation\u003c/code\u003e instances in an array before execution to create ads in bulk.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetErrors\u003c/code\u003e provides error details if ad creation fails, \u003ccode\u003egetResult\u003c/code\u003e returns the new ad if successful, and \u003ccode\u003eisSuccessful\u003c/code\u003e indicates operation success.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code example demonstrates efficient ad creation and label application using an array of \u003ccode\u003eAdOperation\u003c/code\u003e objects.\u003c/p\u003e\n"]]],[],null,["# AdsApp.AdOperation\n\nAn operation representing creation of a new ad. Calling any method ([getErrors](/google-ads/scripts/docs/reference/adsapp/adsapp_adoperation#getErrors), [getResult](/google-ads/scripts/docs/reference/adsapp/adsapp_adoperation#getResult), or [isSuccessful](/google-ads/scripts/docs/reference/adsapp/adsapp_adoperation#isSuccessful)) will cause the operation to execute and create the ad. To make the script more efficient, it's recommended that you store the operations in an array and only call these methods once you've constructed all the operations you want.\n\nFor instance, this is how you would assign a label to newly created ads in\nan efficient manner:\n\n```transact-sql\n// For the purpose of this example, suppose that the fetchAdText() function\n// fetches text ad data from your data source of choice, so that\n// adsToCreate is an array where each element is an object describing an ad.\nvar adgroup = AdsApp.adGroups().get().next();\nvar adsToCreate = fetchAdText();\nvar adOps = [];\nfor (var i = 0; i \u003c adsToCreate.length; i++) {\n adOps.push(\n adGroup.newAd().expandedTextAdBuilder()\n .withHeadlinePart1(adsToCreate[i].headlinePart1)\n .withHeadlinePart2(adsToCreate[i].headlinePart2)\n .withDescription(adsToCreate[i].description)\n .withPath1(adsToCreate[i].path1)\n .withPath2(adsToCreate[i].path2)\n .withFinalUrl(adsToCreate[i].finalUrl)\n .build());\n}\nfor (var i = 0; i \u003c adOps.length; i++) {\n if (adOps[i].isSuccessful()) {\n adOps[i].getResult().applyLabel('myLabel');\n } else {\n Logger.log('Errors from Ad [' + adsToCreate[i].headline + ']: '\n + adOps[i].getErrors());\n }\n}\n```\n\n### Methods:\n\n| Member | Type | Description |\n|---------------------------------|------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| [getErrors()](#getErrors) | `String[]` | Returns an empty array if the operation was successful, otherwise returns the list of errors encountered when trying to create the Ad. |\n| [getResult()](#getResult) | [AdsApp.Ad](/google-ads/scripts/docs/reference/adsapp/adsapp_ad) | Returns the newly created Ad, or `null` if the operation was unsuccessful. |\n| [isSuccessful()](#isSuccessful) | `boolean` | Returns `true` if the operation was successful. |\n\n`getErrors()`\n-------------\n\nReturns an empty array if the operation was successful, otherwise returns the list of errors encountered when trying to create the Ad.\n\n### Return values:\n\n| Type | Description |\n|------------|------------------------------------------------------------------------------------------------------------------|\n| `String[]` | The errors that occurred during the [AdOperation](/google-ads/scripts/docs/reference/adsapp/adsapp_adoperation). |\n\n`getResult()`\n-------------\n\nReturns the newly created Ad, or `null` if the operation was unsuccessful.\n\n### Return values:\n\n| Type | Description |\n|------------------------------------------------------------------|-------------------------------------------------------------------------------------------|\n| [AdsApp.Ad](/google-ads/scripts/docs/reference/adsapp/adsapp_ad) | The [Ad](/google-ads/scripts/docs/reference/adsapp/adsapp_ad) created by the AdOperation. |\n\n`isSuccessful()`\n----------------\n\nReturns `true` if the operation was successful.\n\n### Return values:\n\n| Type | Description |\n|-----------|-----------------------------------------|\n| `boolean` | `true` if the operation was successful. |"]]