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.
Related
I am trying to run a script using executeAsyncScript() method having a fetch call. since fetch call returns a promise, hence on console it is taking some time to fulfill the promise but using selenium java script executer it is throwing error saying script time out,hence I am getting null as output. how can I achive the expected result using selenium executeAsyncScript method.
String str = (String) js.executeAsyncScript("var myHeaders = new Headers();\n" +
"myHeaders.append('client-id', 'LPDP');\n" +
"myHeaders.append('a2z-csrf-token', 'NON_SDF');\n" +
"myHeaders.append('x-amz-rid', 'M6507NCWPW2FVPSSRMVM');\n" +
"\n" +
"let inputEntities = new Map();\n" +
"inputEntities.set(\"Commons$customerId\", \"\\\"A2ZLDCQRXMMNLG\\\"\")\n" +
"inputEntities.set(\"Commons$marketPlaceId\", \"\\\"A2XZLSVIQ0F4JT\\\"\")\n" +
"inputEntities.set(\"Commons$sessionId\", \"\\\"asdb3412\\\"\")\n" +
"inputEntities.set(\"Commons$ubId\", \"\\\"abc\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$eventId\", \"\\\"prsrohitest-1\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$clientId\", \"\\\"HFC\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$useCaseName\", \"\\\"lineItemPromotionPaymentMethodEvent\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$eventTimeStamp\",\"\\\"2022-04-20T21:21:57.934Z\\\"\" )\n" +
"inputEntities.set(\"Rewards$APPA$Commons$category\", \"\\\"HFC\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$subCategory\", \"\\\"PREPAID_RECHARGE\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$requestType\", \"\\\"HFCBP\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$partition\", \"\\\"useCaseName,category,subCategory\\\"\")\n" +
"inputEntities.set(\"Rewards$APPA$Commons$benefitsToBeEvaluated\", \"[\\\"GCCashback\\\",\\\"Coupon\\\",\\\"Membership\\\",\\\"ScratchCard\\\"]\")\n" +
"\n" +
"let entitiesToBeResolved = [\"Rewards$APPA$GetAllPromotions$applicablePromotionDetailList\"]\n" +
"\n" +
"const executeInput = {\n" +
"\"inputEntities\": Object.fromEntries(inputEntities),\n" +
"\"entitiesToBeResolved\": entitiesToBeResolved,\n" +
"};\n" +
"\n" +
"var obj \n" +
"\n" +
"fetch("url", {\n" +
" method: 'POST',\n" +
" headers: myHeaders,\n" +
" body: JSON.stringify(executeInput),\n" +
"})\n" +
" .then(response => response.text())\n" +
" .then(result => obj = result)\n" +
" .then(()=> console.log(obj))\n" +
" .catch(error => console.log('error', error));\n" +
"\n" +
" return obj;");
I am getting null in str variable. Thanks in advance for any help
Note: I'm not in the habit of using java so I don't know how to escape strings properly.
The general way to do this is:
js.executeAsyncScript("arguments[0]('foo')")
You can put that inside a promise's then and it will still work.
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";
In my form I have a total field which is the sum of several checkboxes. When it reaches 21 total page one must be created. below the code, which worked well in another case and this time it gives me a syntax error. someone there you an idea ??
Thank you in advance
this.getField("TOTAL").value =
this.getField("P6eval_competences.manageriales.0").value +
this.getField("P6eval_competences.manageriales.1").value +
this.getField("P6eval_competences.manageriales.2").value +
this.getField("P6eval_competences.manageriales.3").value +
this.getField("P6eval_competences.manageriales.4").value +
this.getField("P6eval_competences.manageriales.5").value +
this.getField("P6eval_competences.manageriales.6").value +
this.getField("P6eval_competences.manageriales.7").value +
this.getField("P6eval_competences.manageriales.8").value +
this.getField("P6eval_competences.manageriales.9").value +
this.getField("P6eval_competences.manageriales.10").value +
this.getField("P6eval_competences.manageriales.11").value +
this.getField("P6eval_competences.manageriales.12").value +
this.getField("P6eval_competences.manageriales.13").value +
this.getField("P6eval_competences.manageriales.14").value +
this.getField("P6eval_competences.manageriales.15").value +
this.getField("P6eval_competences.manageriales.16").value +
this.getField("P6eval_competences.manageriales.17").value +
this.getField("P6eval_competences.manageriales.18").value +
this.getField("P6eval_competences.manageriales.19").value +
this.getField("P6eval_competences.manageriales.20").value +
this.getField("P6eval_competences.manageriales.21").value +
this.getField("P6eval_competences.manageriales.22").value +
this.getField("P6eval_competences.manageriales.23").value +
this.getField("P6eval_competences.manageriales.24").value +
this.getField("P6eval_competences.manageriales.25").value +
this.getField("P6eval_competences.manageriales.26").value +
this.getField("P6eval_competences.manageriales.27").value +
this.getField("P6eval_competences.manageriales.28").value +
this.getField("P6eval_competences.manageriales.29").value +
this.getField("P6eval_competences.manageriales.30").value +
this.getField("P6eval_competences.manageriales.31").value;
if (getField("TOTAL").value == "21") {
var expTplt = getTemplate("NIVEAU MATURE");
expTplt.spawn(numPages, true, false);
}
I think you should use parseInt() method cause the values which are returned are not Integer rather they are Strings.
While porting an android app to iOS we hit a barrier:
We have a UIwebView set up to run HighCharts (it works with their provided sample), but we can't figure out how to pass variables to Javascript in order to display real time changes.
The android-equivalent of what we're trying to do is:
webView.loadUrl("javascript:" + "point = " + "[Date.UTC("
+ mYear + "," + mMonth + "," + mDay + "," + hr
+ "," + min + "," + sec + "),"
+ value+ "];");
or another example:
webView.loadUrl("javascript:" + "var curve_name = " + "'Illuminance';" +
"var unit_of_meas = " + "'lx';" +
"var x_axis_title = " + "'Date';" +
"var y_axis_title = " + "'Illuminance (lx)';" +
"var plot_title = " + "'Illuminance data';" +
"var plot_subtitle = " + "'';")
UIWebView has a method called stringByEvaluatingJavaScriptFromString that you can use to run a script. I think that you can also use it to just pass and initialize any variable that you like.
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"]