Exporting Google Ads Calls to Sheets From Campaigns - google-ads-api

function main() {
var spreadsheet = SpreadsheetApp.create("Report output");
var report = AdsApp.report("SELECT metrics.phone_calls, " +
"FROM campaign " +
"WHERE segments.date BETWEEN '2022-01-01' AND '2022-07-03'");
report.exportToSheet(spreadsheet.getActiveSheet());
Logger.log("Report available at " + spreadsheet.getUrl());}
Returning this error: Exception: Call to GoogleAdsService.Search failed: Error in SELECT clause: invalid field name 'FROM'.
How can I make this work?

Related

How to compute the Google Query's data field?

how can I compute QUERY's data attribute to make data range dynamic?
More details: I have a spreadsheet with multiple worksheets incl. a separate "summary" one. Here, a couple of queries are aggregating data from these multiple sheets. All fine. But: any time I add/remove a sheet, I will have to update all queries manually - which is quite cumbersome. So I created a small script that returns the names of all worksheets. Nice.
What I have trouble with: how can I make QUERY() accept these worksheet names? It returns #value.
originally:= QUERY({'sheet 1'!$A:$C; 'sheet 2'!$A:$C}; "SELECT SUM(Col2), ...") //works.
with script:= QUERY(getSheetNames(); "SELECT SUM(Col2), ...") //#value error
add script to cell and referencing cell:= QUERY(A1; "SELECT SUM(Col2), ...") //#value error
custom function:getSheetNames() currently returns "{'sheet 1'!$A:$C; 'sheet 2'!$A:$C}"
function getSheetNames() {
var out = "";
var columns = "!$A:$C";
var apostrophe = "'";
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i = 1 ; i < sheets.length; i++) {
out += apostrophe + sheets[i].getName() + apostrophe + columns + "; ";
}
out = "{" + out.slice(0, -2) + "}";
return out;
}
Many thanks for help!

Google Ads Script (AWQL) get custom date range for reporting

I need to pull a google ads report that will get data from a fixed date (28th May) until today and push the data to a spreadsheet. I can't figure out how to define the date range for this query
I've tried googling and reading the google documentation but I can't figure it out
function main() {
var spreadsheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/XXX');
var sheet = spreadsheet.getSheetByName('Data')
var report = AdsApp.report(
'SELECT Date, CampaignName, AverageFrequency, Impressions, ImpressionReach ' +
'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
'WHERE Impressions > 0 ' +
'DURING 20190528,TODAY');
sheet.clearContents();
report.exportToSheet(sheet);
}
I need to use today as the end date instead of the campaign end date as the end date for this query as I'm trying to pull frequency as a metric and it will just show blank values if the end date is in the future.
Please let me know if there is a way to make the query work. Thanks!
The TODAY keyword acts as the "full range" of the DURING property and cannot be used as the end part (as far as I know). The following should work.
function main() {
var endDate = new Date();
var endRange = Utilities.formatDate(endDate, 'America/Chicago', 'YYYYMMdd');
var spreadsheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/XXX');
var sheet = spreadsheet.getSheetByName('Data')
var report = AdsApp.report(
'SELECT Date, CampaignName, AverageFrequency, Impressions, ImpressionReach ' +
'FROM CAMPAIGN_PERFORMANCE_REPORT ' +
'WHERE Impressions > 0 ' +
'DURING 20190528,' + endRange);
sheet.clearContents();
report.exportToSheet(sheet);
}
Date ranges for the report are defined in the DURING clause of the query. Date ranges can be specified in two different ways:
A custom date range using regular AWQL syntax, for example:
SELECT Id, Criteria, AdGroupName
FROM KEYWORDS_PERFORMANCE_REPORT
DURING 20190101,20190325
A date range type, for example:
SELECT Id, Criteria, AdGroupName
FROM KEYWORDS_PERFORMANCE_REPORT
DURING LAST_7_DAYS
In your case you should use:
DURING 20190528, 20190723
There is no other option for you to do that.

WIQL query to get all item under a workitem

I am looking for a query where i can return all work items and their relation from a area path.
for example : project 1
i need all Featured all Userstories mapped to it all workitem and Bug mapped to userstories,
in short if i took a bug from the object i need somthing like parent id where i can match with the userstory.
string query1 = " SELECT * FROM WorkItemLinks " +
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
which throwing an error like below
An exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll but was not handled in user code
Additional information: TF51005: The query references a field that does not exist. The error is caused by «[System.IterationPath]».
when i checked the dll's are refereed correctly and when i re wrote the query like this the query is working fine
string query = " SELECT * FROM WorkItems"+
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
//" AND ([System.State] = 'Active' OR [System.State] = 'Assessed' ) "+
//" AND ( [Microsoft.VSTS.Scheduling.StartDate] <= '09/13/2017' AND [Microsoft.VSTS.Scheduling.FinishDate] >= '09/13/2017' )"+
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
but this query result does not give the relation ship that if a work item mapped as a child to other i need parent id in the work item object. how to get that. Thanks in advance.
You can try below query:
Install Nuget Package Microsoft.TeamFoundationServer.ExtendedClient for the project.
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
namespace _0925_WIQL
{
class Program
{
static void Main(string[] args)
{
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
new Uri("http://server:8080/tfs/CollectionLC"));
WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore));
string query1= " SELECT * FROM WorkItemLinks " +
" WHERE ( Source.[System.IterationPath] Under 'TeamProject\\Iteration 1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
Query query = new Query(workItemStore, query1);
WorkItemLinkInfo[] witLinkInfos = query.RunLinkQuery();
foreach (WorkItemLinkInfo witinfo in witLinkInfos)
{
.......
}
Besides, you can also use Wiql Editor. If you want to get all the parent workitems (IDs) from a specific child work item (ID), you can use below WIQL:
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State]
FROM workitemLinks
WHERE ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND ([Target].[System.Id] = 25)
ORDER BY [System.Id]
MODE (Recursive, ReturnMatchingChildren)

FireDAC Query connect to DBGrid

I have FDQuery and DataSource and DBGrid. Now I write this code in Button
FDQuery2->Active = false;
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = " + MaskEdit1->Text +
" ORDER BY C.check_id ");
FDQuery2->Active = true;
and i connect FDQuery to DataSource and tDataSource to DBGrid, but when I click the Button it doesn't show rows. and i am sure that SQL code is work, because when i write inside the SQL String the rows have been shown.
any ideas.
You're missing the ' around your value when concatenating the text. Change your WHERE clause:
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = '" + MaskEdit1->Text + "'" +
" ORDER BY C.check_id ");
You really should learn to use parameterized queries instead, though. It allows the database driver to handle things like properly quoting text or formatting dates for you, and it also (importantly) prevents SQL injection.
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = :today" +
" ORDER BY C.check_id ");
FDQuery2->ParamByName("today")->AsString = MaskEdit1.Text;
FDQuery2->Active = true;

Invalid column name error

I am trying to sort by transient property but fails with SQL Error: Invalid column name error .
Pls find below my code :
In domain class declared :
static transients = ['sortCandidateLastName']
Query which I am trying to execute:
When I am trying to run the below query in Oracle :It runs fine
( select * from ( select row_.* ,rownum rownum_ from ( select * from booking b where b.marked_deleted='N' order by (select c.cand_id from candidate c where b.cand_id = c.cand_id) asc ) row_ where rownum <= 15 ) where rownum > 0)
GSP code:
<g:sortableColumn property="sortCandidateLastName" title="Sort By Candidate Last Name" />
But when Hibernate is trying to read it ,it throws Invalid column name : ResultSet.getInt(clazz_)
Transient properties are not persisted so it's impossible to write a query which sorts by a transient property. If you retrieve a list of objects from a query and want to sort them by a transient property, you'll have to do it in Groovy code, e.g.
// an example domain class with a transient property
class Book {
private static Long SEQUENCE_GENERATOR = 0
String isbn
String title
Long sequence = ++SEQUENCE_GENERATOR
static transients = ['sequence']
}
// get a list of books from the DB and sort by the transient property
def books = Book.list()
books.sort { it.sequence }
You cant sort on transient field. There is no actual database column for a transient field! So your sql would always throw an error!
I tried using jdbcTemplate and gives me the required functionality.
Code snippet:
GSP Layer:
<g:sortable property="sortCandidateLastName">
<g:message code="booking.alphabetical.label" default="Alphabetical(A-Z)" />
</g:sortable>
Domain layer:
just defined a transient property :
static transients = ['sortCandidateLastName']
Reason for adding the transient field : SO that it doesn't throw me any exception like missing property.
Controller layer :
if(params.sort == "sortCandidateLastName" )
{
bookingCandList= bookingService.orderByCandidateLastName(params.max, params.order,params.offset.toInteger())//Booking.getSortCandidateLastName(params.max, params.order,params.offset.toInteger()) //
}
Service layer :
def jdbcTemplate
public List orderByCandidateLastName(Integer max, String sortOrder,Integer offset) {
println "Inside the getcandidateLastName ${max} :: offset ${offset}"
def sortedList
int minRow = offset
int maxRow = offset+max
String queryStr = " select * from " +
" ( "+
" select row_.* " +
" ,rownum rownum_ " +
" from " +
" ( " +
" select * from booking b where b.item_id= 426 and b.marked_deleted='N' order by " +
" (select c.cand_id from candidate c where b.cand_id = c.cand_id) ${sortOrder} "+
" ) row_ "+
"where rownum <= ${maxRow} " +
") " +
"where rownum > ${minRow}"
return jdbcTemplate.queryForList(queryStr)
}
Configuration of JDBC template :
// Place your Spring DSL code here
import org.springframework.jdbc.core.JdbcTemplate
beans = {
..........
jdbcTemplate(JdbcTemplate) {
dataSource = ref('dataSource')
}
}
Hope it helps to ..
Cheers

Resources