I have a Google Apps Script I am writing that combines a number of reports into a consolidated tab-delimited (TSV) format. However, I am noticing that whenever I write to file, the tabs in my strings are being converted into spaces. Is there some other string literal that I should use?
var content =
data.parameters.time[0] + "\t" +
data.parameters.url[0] + "\t" +
data.parameters.code_name[0] + "\t" +
data.parameters.app_name[0] + "\t" +
data.parameters.version[0] + "\t" +
data.parameters.cookies[0] + "\t" +
data.parameters.lang[0] + "\t" +
data.parameters.platform[0] + "\t" +
data.parameters.user_agent[0] + "\t" +
data.parameters.ex[0];
fld.createFile(makeid() + ".tab", content, ContentService.MimeType.CSV);
Nothing is wrong with using the \t string literal - rather you're using the wrong MimeType enum, from the ContentService. DriveApp methods expect MimeType as a string. Try:
fld.createFile(makeid() + ".tab", content, MimeType.CSV);
Here's a snippet that shows the tab characters survive the file write when the MimeType is properly set:
function myFunction() {
var content =
'time' + "\t" +
'url' + "\t" +
'code_name' + "\t" +
'etcetera';
Logger.log("Initial TSV: " + JSON.stringify(content.split("\t")));
var newFile = DriveApp.createFile("Delete-me" + ".tab", content, MimeType.CSV);
// Check our result, by reading back the file
var blob = newFile.getBlob();
var docContent = blob.getDataAsString()
Logger.log("Result TSV: " + JSON.stringify(docContent.split("\t")));
}
Logs:
[15-04-07 14:53:08:767 EDT] Initial TSV: ["time","url","code_name","etcetera"]
[15-04-07 14:53:09:542 EDT] Result TSV: ["time","url","code_name","etcetera"]
Related
I am working with Square POS API and have successfully sent a request to the android app via a mobile web app. The app opens, displays the correct price, accepts payment and returns to the callback URL.
I have read over the documentation a few times and may be missing it but is there a way I can add a Unique ID that is sent to the app and returned to the callback page so I can update the correct line item in the database?
possibly something like:
"l.com.squareup.pos.UNIQUE_ID=" + unique_id + ";" +
var posUrl =
"intent:#Intent;" +
"action=com.squareup.pos.action.CHARGE;" +
"package=com.squareup;" +
"S.com.squareup.pos.WEB_CALLBACK_URI=" + callbackUrl + ";" +
"S.com.squareup.pos.CLIENT_ID=" + applicationId + ";" +
"S.com.squareup.pos.API_VERSION=" + sdkVersion + ";" +
"i.com.squareup.pos.TOTAL_AMOUNT=" + transactionTotal + ";" +
"S.com.squareup.pos.CURRENCY_CODE=" + currencyCode + ";" +
"S.com.squareup.pos.TENDER_TYPES=" + tenderTypes + ";" +
"l.com.squareup.pos.AUTO_RETURN_TIMEOUT_MS=" + callbacktime + ";" +
"l.com.squareup.pos.UNIQUE_ID=" + unique_id + ";" +
"end";
My user show pages have URL's that look like this: "https://ee55715a523f4af8bae9f5467daf644d.vfs.cloud9.us-east-2.amazonaws.com/users/1". I am trying to grab the user id from the end using a regex, and I know that this should work: [/\d+$/]. Here is the code:
$(document).ready(function(){
$("#userplans").on('click', function(e) {
debugger;
$.get("/fitness_plans", function(data) {
for (let i=0; i<data.length; i++) {
const userId = $("#userId");
debugger;
if (data[i]["user_id"] === userId.innerText) {
$("#plans").append("<li>" + "Name: " + data[i]["workout_routine"]["name"] + "</li>")
.append("<li>" + "Length(days): " + data[i]["duration"] + "</li>")
.append("<li>" + "Category: " + data[i]["workout_routine"]["category"] + "</li>")
.append("<li>" + "Difficulty: " + data[i]["difficulty"] + "</li>")
.append("<li>" + "Days per Week: " + data[i]["split_length"] + "</li>")
}
}
})
})
})
;
When I enter the debugger and type "e.target.baseURI" I get the above url. However, when I type "e.target.baseURI[/\d+$/]" or "e.target.baseURI.match([/\d+$/])", I get undefined and null, respectively. What am I doing wrong?
The code includes the quantifier + and boundary $ characters within the character set, use /\d+$/ without surrounding brackets (character set)
"https://ee55715a523f4af8bae9f5467daf644d.vfs.cloud9.us-east-2.amazonaws.com/users/1"
.match(/\d+$/)
I use a JavaScript blob to create an FDF file which opens & fills in a locally stored PDF.
However, the file path to the locally stored PDF contains an accented character (and I am unable to edit the folder name).
This code works when the folder path doesn’t contain an accent and if I open the fdf in Notepad, the default encoding is ANSI. But when the folder path contains an accent, the FDF opens to a message stating the PDF cannot be found. Furthermore, the default encoding in Notepad has changed to UTF-8.
FDF_Text = ''
+ '%FDF-1.2' + "\n"
+ '1 0 obj<</FDF<</F(T:/Échange/MY_PDF.pdf)/Fields 2 0 R>>>>' + "\n"
+ 'endobj' + "\n"
+ '2 0 obj[' + "\n"
+ '<</T(FIELD_NAME)/V(SOME_TEXT)>>' + "\n"
+ ']' + "\n"
+ 'endobj' + "\n"
+ 'trailer' + "\n"
+ '<</Root 1 0 R>>' + "\n"
+ '%%EO'
var blobObject = new Blob([FDF_Text], {type: 'text/css;charset=ANSI'});
window.navigator.msSaveOrOpenBlob(blobObject, 'MY_FDF.fdf');
I have tried
replacing É with E
using String.fromCharCode(201) (the chr value for É)
changing & removing the "type" of the blob itself to several different examples I've found (sorry I didn't keep track of all the different combinations).
Can anyone suggest a different solution?
You can represent the data as binary, just run through the string and fill a binary array
FDF_Text = ''
+ '%FDF-1.2' + "\n"
+ '1 0 obj<</FDF<</F(T:/Échange/MY_PDF.pdf)/Fields 2 0 R>>>>' + "\n"
+ 'endobj' + "\n"
+ '2 0 obj[' + "\n"
+ '<</T(FIELD_NAME)/V(SOME_TEXT)>>' + "\n"
+ ']' + "\n"
+ 'endobj' + "\n"
+ 'trailer' + "\n"
+ '<</Root 1 0 R>>' + "\n"
+ '%%EO'
var uint8 = new Uint8Array(FDF_Text.length);
for (var i = 0; i < uint8.length; i++){
uint8[i] = FDF_Text.charCodeAt(i);
}
var blobObject = new Blob([uint8], {type: 'text/fdf'});
window.navigator.msSaveOrOpenBlob(blobObject, 'MY_FDF.fdf');
I have shell command which runs batch file with parameters below code all works fine
WshShell.Run ( '"H:\\Workspace\\testcomplete\\TCAF - QIKSilver\\test.bat" ' + + a + ' ' + b + ' ' + c);
The batch file path is not constant I would like to pass it dynamically
d= Project.Path; // I get the path of my project
value = d.replace(/\\/g, "\\\\");// replace single backslash with double slash
filepath = value.concat("test.bat") // value of filepath varialbe is -H:\\Workspace\\testcomplete\\TCAF - QIKSilver\\test.bat
Following is not working:
WshShell.Run ('filepath' + a + ' ' + b + ' ' + c);
any suggestions please
This code is written inside test complete using java script
You need to use filepath as a variable, not string, and you need to add quotes since your path contains spaces:
WshShell.Run('"' + filepath + '" ' + a + ' ' + b + ' ' + c);
Try this:
WshShell.Run (filepath+' '+ a + ' ' + b + ' ' + c);
Can anybody help to assign this xml as constant string in javascript. How to assign this xml as constant without any changes?
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">
" +
"<wp:Tile>
" +
"<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" +
"<wp:Count>" + TextBoxCount.Text + "</wp:Count>" +
"<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" +
"<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" +
"<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" +
"<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" +
"
</wp:Tile> " +
"
</wp:Notification>";
Thanks in advance
JavaScript doesn't have a constant modifier.
Closest you could do is define it with defineProperty() and set writable to false.
Also, your string...
"<wp:Tile>
" +
...won't work as the parser currently doesn't support multiline strings. You'll need to break it up with " + " or use the escape character as the last character.