google adwords script - find accounts with label - scripting

We have many accounts we manage and the ones we are interested have the label 'Active Clients'. This label is shown on the first page of the MCC ('My Client Center') in the table. It is the second column of the table that shows 'Labels'.
Here's the basic script:
function main() {
var accountSelector = MccApp.accounts()
.withCondition("Labels = 'Active Clients'");
var accountIterator = accountSelector.get();
// Iterate through the list of accounts
while (accountIterator.hasNext()) {
var account = accountIterator.next();
// Select the client account.
MccApp.select(account);
// Operate on client account
Logger.log('Customer ID: ' + account.getCustomerId() );
}
}
This is how I'm trying to iterate through all clients that have the label 'Active Clients'. It doesn't work and I'm wondering if it can be made to work or I must specify the id's of all clients.

The column name is LabelNames instead of Labels. Also its type is StringSet, not String, so you should use .withCondition("LabelNames CONTAINS_ANY ['Active Clients']"). However, "LabelNames" is not an available column for AccountSelector conditions yet (https://developers.google.com/adwords/scripts/docs/reference/mccapp/mccapp_accountselector#withCondition_1), hope this will change by time.
Anyway, I recommend to create a new MCC, where you keep only active clients, so you can place the script there without using withCondition.

Related

How to loop google-Apps script?

I would like to gather subscribers for the channel id of youtube with an app script on Google Spreadsheets. But it only worked with one id.
I'd like to use a repeat statement, but I can't because I'm not good enough. I'd appreciate it if you could help me.
function getChannelInfo() {
var ss = SpreadsheetApp.getActiveSheet();
var channel = ss.getRange("B2").getValue();
var data = YouTube.Channels.list('statistics', {id: channel});
var item = data.items[0];
var info = [item.statistics.subscriberCount];
ss.getRange("C2").setValues([info]);
}
I want to gather subscribers for all video IDs in column B, but only one comes out. Help me.
https://docs.google.com/spreadsheets/d/1Ks_tE9uDdOcTKML8jf_40lJpcImMoh-JYivpV38zpCk/edit?usp=sharing
No problem
In this statement var channel = ss.getRange("B2").getValue();, you are calling just one value. Instead you should go with an array of values. Like ss.getrange(row, colum, number of rows).getdisplayvalues();
use FOR LOOP to run for each value in the above array and set values in the Spreadsheet in the corressponding cells.
Let me know if you need help :)

Is there a way to export only newly created/modified users from LDAP everyhour?

I am trying to create a LDAP filter that brings in only the newly created/updated users. I am planning to schedule this job to run every hour. So, I shall have the newly created/updated users from AD to servicenow every hour.
I tried to use (modifytimestamp) method, but the Zulu date is hardcoded. How to make it filter every hour? I mean, the filter should be (modifyTimeStamp >=(now - 1hr))
(&(objectClass=inetOrgPerson)(!(renaccountsuspended=1))(modifyTimeStamp>=20190418123800Z))
This is probably not recommended practice, but you could use a scheduled script execution job to update the filter on your ldap ou config every day in conjunction with the whenChanged ldap attribute. Something like this maybe (untested):
Scheduled job every day:
var gr = new GlideRecord('ldap_ou_config');
gr.get('name','Users'); //or whatever your filter is uniquely named
var curFilter = gr.filter;
//(&(objectClass=person)(whenChanged>=20190704000000.0Z)(sn=*)(!(objectClass=computer))(!(userAccountControl:1.2.840.113556.1.4.803:=2)));
var curDate = curFilter.substr(curFilter.indexOf('whenChanged>=') + 13,8);
var today = new GlideDateTime().toString().split(' ')[0].split('-').join('');
curFilter = curFilter.replace(curDate, today);
gr.filter = curFilter;
gr.update();
You need to enable the LDAP listener.
Relevant documentation

How to convert Thunkable sql commands to Google Apps Script and link directly to a Fusion Table

I have succeeded using Thunkable to archive old data in a Fusion Table. I would like this to be done in the background of the app using Google Apps Script.
The Thunkable Blocks with SQL is as follows:
Query 1:
SELECT ROWID FROM TableID WHERE Duration<= Clock.Now
SET GLOBAL RESULTS to List from CSV Table text (Result from Query1)
For each number from 2 to length of list by 1 DO Query 2
Query 2:
UPDATE TableID SET Availability='uNAVAILABLE' WHERE ROWID='list item 2 from result from Query 1'
Remove list item 2
Query 3:
DELETE FROM TableID WHERE Availability='Unavailable'
How can I convert this to Google Apps Script and link it to a Fusion Table? Thank you.
Per documentation,
A quick way to try out the API is to type the command or query directly into your browser's toolbar. You can adjust the URL as you change your query or data needs and you'll get immediate feedback. You can only do this with tables that are exportable and either public or unlisted, and you need to include your API key.
Here's a sample that runs a query to select all rows in a given table,
https://www.googleapis.com/fusiontables/v2/query?sql=SELECT * FROM 1KxVV0wQXhxhMScSDuqr-0Ebf0YEt4m4xzVplKd4&key={your API key}
So, to implement this using Google Apps Script, try using Class UrlFetchApp.
Fetch resources and communicate with other hosts over the Internet. This service allows scripts to communicate with other applications or access other resources on the web by fetching URLs. A script can use the URL Fetch service to issue HTTP and HTTPS requests and receive responses.
You may want to check this sample Google Apps script and fusion table query in this GitHub post for additional insights.
function readFacName(fac, city){
// public fusion table
// https://www.google.com/fusiontables/DataSource?docid=1tL67aacGcCyMfAg9PUo_-gp4qm74GDtFiCMtFg
var select = "select FACNAME from 1tL67aacGcCyMfAg9PUo_-gp4qm74GDtFiCMtFg ";
var where = "where FAC_ZIP5 = '" + fac + "' AND FAC_CITY = '" + city +"'";
var query = encodeURIComponent(select + where);
var url = "http://www.google.com/fusiontables/api/query?sql=" + query;
var response = UrlFetchApp.fetch(url, {method: "get"});
return response.getContentText();
}
function fTable() {
Logger.log(readFacName("94609","OAKLAND"));
}

CRM Dynamics Update Option Set Values with data from another sql table

Hi I am a bit stuck with regards to automatically updating a CRM Option Set value with data from another external SQL table, I have a requirement to update CRM option sets when a value in an external table is updates as a new value, I know that updating the MSCRM SQL db is not supported and I was wondering what would be a different way to do it in an automated way. Your help will be very grateful.
You can update specific values in a global or local option set by using UpdateOptionValueRequest
MSDN has an example of how to use this request:
// In order to change labels on option set values (or delete) option set
// values, you must use UpdateOptionValueRequest
// (or DeleteOptionValueRequest).
UpdateOptionValueRequest updateOptionValueRequest =
new UpdateOptionValueRequest
{
OptionSetName = _globalOptionSetName,
// Update the second option value.
Value = optionList[1].Value.Value,
Label = new Label("Updated Option 1", _languageCode)
};
_serviceProxy.Execute(updateOptionValueRequest);
//Publish the OptionSet
PublishXmlRequest pxReq3 = new PublishXmlRequest { ParameterXml = String.Format("<importexportxml><optionsets><optionset>{0}</optionset></optionsets></importexportxml>", _globalOptionSetName) };
_serviceProxy.Execute(pxReq3);
You would detect changes in the SQL and use a query similar to the above to update the option set.

How do you get Endeca to search on a particular target field rather than across all indexed fields?

We have an Endeca index configured across multiple fields of email content - subject and body. But we only want searches to be performed on the subject lines. Endeca is returning matches within the bodies too. How do you limit the search to the subject?
You can search a specific field or fields by specifying it (them) with the Ntk parameter.
Or if you wish to search a specific group of fields frequently you can set up an interface (also specified with the Ntk parameter), that includes that group of fields.
This is how you can do it using presentation API.
final ENEQuery query = new ENEQuery();
final DimValIdList dimValIdList = new DimValIdList("0");
query.setNavDescriptors(dimValIdList);
final ERecSearchList searches = new ERecSearchList();
final StringBuilder builder = new StringBuilder();
for(final String productId : productIds){
builder.append(productId);
builder.append(" ");
}
final ERecSearch eRecSearch = new ERecSearch("product.id", builder.toString().trim(), "mode matchany");
searches.add(eRecSearch);
query.setNavERecSearches(searches);
Please see this post for a complete example.
Use Search Interfaces in Developer Studio.
Refer - http://docs.oracle.com/cd/E28912_01/DeveloperStudio.612/pdf/DevStudioHelp.pdf#page=209