issues with google-dfp %%PATTERN:key%% - google-dfp

Do anyone know how DFP macros work ?
in que banner I have code that look like:
var marque = '%%PATTERN:make%%';
var modele = '%%PATTERN:model%%';
The macros are not being replaced. I wondered if it's not because my variable are not the same ? should I write it like that ?
var make = '%%PATTERN:make%%';
var model = '%%PATTERN:model%%';

Related

How can I get an UmbracoHelper in an HttpHandler?

In Umbraco 7 you could use UmbracoContext.EnsureContext() and some trickery to get an UmbracoHelper outside of an Umbraco context, such as in an HttpHandler. In Umbraco 8 UmbracoContext.EnsureContext() has been removed so how can we do this now?
Specifically I want to get the root node, in my HttpHandler like
var helper = CreateUmbracoHelper();
var root = helper.ContentAtRoot().First();
But I can't figure out how I might implement CreateUmbracoHelper().
Turns out it's pretty simple using the DependencyResolver. Here's what I've got and it works perfectly.
var factory = DependencyResolver.Current.GetService<IUmbracoContextFactory>();
using (factory.EnsureUmbracoContext())
{
var helper = DependencyResolver.Current.GetService<UmbracoHelper>();
var websiteNode = helper.ContentAtRoot().Single() as HomePage;
// etc
}

How to return all entries from specific date in log.nsf

I need to return all entries (collection) from a specific date from the miscellaneus view in log.nsf using SSJS.
The views first category is "text" and the second category is a "date".
I tried to use the methods getAllEntriesByKey(vector) or createViewNavFromCategory(vector) but I got kind of stuck as the categorized columns contain different data types.
how can I do that?
Here is one thing I tried
var logdb = sessionAsSigner.getDatabase("domino01/....","log.nsf");
var logView = logdb.getView("MiscEvents")
var v = new java.util.Vector()
var nav = logView.createViewNavFromCategory("domino01/...\\2019-02-15")
return nav.getCount()
and here is another
var logdb = sessionAsSigner.getDatabase("domino01/...","log.nsf");
var logView = logdb.getView("MiscEvents")
var v = new java.util.Vector()
v.add("domino01/...")
v.add(session.createDateTime("Today").getDateOnly())
var nav = logView.getAllEntriesByKey(v)
return nav.getCount()
Just remove the getDateOnly call from your 2nd example code.
v.add(session.createDateTime("Today"))

change output file encoding in a google-script with DriveApp.createFile?

Let's explain the context of my request : I'm trying to output the content of a google spreadsheet in a .txt tabulated file, encoded in UTF-16, because I need this charset in a later task with this .txt file.
Actually, I've got the right output in the right folder and with the name I want ect ... but the charset is UTF-8 (i've check with an basic text editor).
The problem is I can't find any documentation about charset manipulation with google script. My only solution for now, is a basic manual charset manipulation in sublim text ...
Here's my code (translated from french).
Thank's for your replies !
Maxime
function export() {
//sheet manipulation part
//Get the sheet and set data range i need
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getDataRange();
var values = sheet.getRange(2, 1, sheet.getLastRow()-1, sheet.getLastColumn()).getValues();
var text = values.map(function (a) {return a.join('\t');}).join('\n');
//Path setting and export part
// Get sheet info, define path and create file
var id = SpreadsheetApp.getActiveSpreadsheet().getId();
var idString = id.toString();
var thisFile = DriveApp.getFileById(idString);
var parentFold = thisFile.getParents();
var folder = parentFold.next();
var theId = folder.getId();
var targetFolder = DriveApp.getFolderById(theId);
targetFolder.createFile('liste du ' + new Date() + '.txt', text, MimeType.PLAIN_TEXT);
}
This helped me:
var string = 'your text here';
var blob = Utilities.newBlob('').setDataFromString(string, "UTF-16");
blob.setName('your_file_name.txt');
var file = DriveApp.createFile(blob);
As a result createFile method will use UTF-16.
This has already been answered in this SO post:
Utilities.newBlob("").setDataFromString("foo", "UTF-8").getDataAsString("UTF-16")

Script to name form response spreadsheet based on form title in Google Drive

I need a script to be able to create the form response spreadsheet of a Google Form and name that Spreadsheet the same as the Form + (Responses) at the end of the name. I have no idea how to do this. I am guessing it has to do with the script below, but the script does not understand that "Title" is the same as a "Name". (I do not know how to append the "(Responses)" part at the end either.) Any help would be appreciated.
function myFunction() {
var form = FormApp.openById('FORM ID HERE').getTitle();
var ss = SpreadsheetApp.create(form);
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
}
I found the answer and also how to apply it to many forms in a folder. The answer is below.
function myFunction() {
var files = DriveApp.getFolderById("0B6Eeub3cEBoobnpxWXdjSWxJRm8").getFiles()
while (files.hasNext()) {
var file = files.next();
var form = FormApp.openById(file.getId());
var formName = DriveApp.getFileById(file.getId()).getName();
var ss = SpreadsheetApp.create(formName + ' (Responses)');
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
}
}

Sapui5 load Data pass by parameter

I am learning sapui5. I want pass my model data vitw parameter. I tried this but I think this is very bad a choice. How can I fix this?
var view = this.getView();
var model = new sap.ui.model.json.JSONModel();
var variable="testVariable";
model.loadData("......format=json&key=selectbyname&Name=" +variable+ ");
view.setModel(model);
You simply need to build the URL as string
var variable = "testVariable";
var url = "http://www.example.org/models?type=json&name=" + variable;
model.loadData(url);
view.setModel(model);
in your case it should be enough if you delete the bold part, so that you receive valid javascript:
model.loadData("......format=json&key=selectbyname&Name=" +variable + ");
to
model.loadData("......format=json&key=selectbyname&Name=" + variable );