while (iterator.hasNext()) {
var entity = iterator.next();
if(entity.getEntityType() === 'Campaign' && entity.getEndDate() != null) {
var accountTimeZone = AdsApp.currentAccount().getTimeZone();
var campaignEndDate = entity.getEndDate();
var accountDateTodayString = Utilities.formatDate(new Date(), accountTimeZone, 'MM/dd/YYYY');
var dateToday = new Date(accountDateTodayString);
var formattedCampaignEndDate = new Date(campaignEndDate.month + '/' + campaignEndDate.day + '/' + campaignEndDate.year);
if(formattedCampaignEndDate < dateToday) {
entities.push(entity);
}
} else {
entities.push(entity);
}
}
Let me know if you need anything else.
|
||||||
| 10/1/2022 16:00:37 | TypeError: Cannot use instanceof on a non-object. (file Code.gs, line 35) |

Consulting Office : ĐÀO LÊ PHƯƠNG
Tel : 090.33.000.64 - 0961.784.130
Email : phuongdaon...@gmail.com
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/-JJyQ000000000000000000000000000000000000000000000R5HKS400_wb-5dhESAaLhh2wfSyuUw%40sfdc.net.
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
if (campaign.getEndDate() != null) {
var accountTimeZone = AdsApp.currentAccount().getTimeZone();
var campaignEndDate = entity.getEndDate();
var accountDateTodayString = Utilities.formatDate(new Date(), accountTimeZone, 'MM/dd/YYYY');
var dateToday = new Date(accountDateTodayString);
var formattedCampaignEndDate = new Date(campaignEndDate.month + '/' + campaignEndDate.day + '/' + campaignEndDate.year);
if (formattedCampaignEndDate < dateToday) {
campaignIds.push(campaign.getId());
}
}
}
Let me know if you are still unable to achieve your requirement. Hi Harry,
I'm new with coding, could you pass me the code to insert, I’m not entirely sure of how the logic works there.
Thanks,
Alberto
var campaign = AdsApp.campaigns().withCondition('CampaignName =' + entityDetails).get().next();
if (campaign.getEndDate() != null) {
var accountTimeZone = AdsApp.currentAccount().getTimeZone();
var campaignEndDate = campaign.getEndDate();
var accountDateTodayString = Utilities.formatDate(new Date(), accountTimeZone, 'MM/dd/YYYY');
var dateToday = new Date(accountDateTodayString);
var formattedCampaignEndDate = new Date(campaignEndDate.month + '/' + campaignEndDate.day + '/' + campaignEndDate.year);
if (formattedCampaignEndDate < dateToday) {
// If valid, return true.If invalid, return false.
}
}