I am using sap.m.MultiInput. How to send that data to the SAP Backend?
I tried using a loop:
for(var i = 0; i < oLenght; i++) {
var oData = this.getView().byId("myMultiInputControl").getTokens()[i].getKey();
}
But oData is holding always a new value. How to hold the data?
you can use a delimiter for example ("/" character) between the keys of the multinput and send the data to the backend System :
if(oMultiInputElement.tokens.length > 1) {
var dataToSend = "";
for(var i = 0; i < oMultiInputElement.tokens.length; i++) {
dataToSend = oFilterData.tokens[i].key + "/" + dataToSend;
}
} else {
dataToSend = oMultiInputElement.tokens[0].key;
}
Related
I have been using the getEditResponseUrl method for quite some time. However now in the list of over 400 entries some of the urls which are generated end up with a blank form instead of the previously added content. Any idea on solving this?
function linksmaken() {
var urlCol = 64; // kolom nr 64 begint met 1
var responses = form.getResponses();
for (var i = 0; i < responses.length; i++) {
timestamps.push(responses[i].getTimestamp().setMilliseconds(0));
urls.push(responses[i].getEditResponseUrl());
}
for (var j = 1; j < data.length; j++) {
resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
}
sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);
}
I have the following code with which I have to extract the last email arrived with the label 'AlertGol', then I have to process it by cutting the parts that I do not need and send it back to me by email. Something I'm doing wrong because I get more than 3 emails including one undefinied.
function getEmails() {
var label = GmailApp.getUserLabelByName("AlertGol");
var thread = label.getThreads();
for (var i = 0; i < thread.length; i++) {
var messages = thread[i].getMessages();
for (var j=0; j<messages.length; j++)
{
var msg = messages[j].getPlainBody();
var trim = msg.substring(5,15);
var trim1 = msg.substring(40, 90);
var tot = trim+trim1;
}
GmailApp.sendEmail(Session.getEffectiveUser().getEmail(), 'Subject', tot);
}
When I am on my electronic site, my app finds about 6000. Each page has about 18 items. I can control how many items per page by setting the PRODUCT_PER_PAGE. This is my firs app in angular 2 and I am trying to built a large scale shopping cart. My app takes about 2 seconds to display 18 pages. Is this normal? By the way, below is the my code select a page. Thanks in advance.
onSelectPage(thePage: string) {
//page(1/4) /*
/* var slash = Number(page.indexOf('/'));
var length = slash - 5;
page = page.substr(5, length); */
let page = Number(thePage);
let productDisplay = this._searchProductService.products;
this.products = [];
this.productsNextColumn = [];
let pageNumber = Number(page) - 1;
this.pageNumber = pageNumber;
this.pageDisplay = pageNumber + 1;
if(this.isClicked) {
productDisplay = this.theClickedQueries;
if(productDisplay.length > 0)
productDisplay = this.theClickedQueries;
else
productDisplay = this._searchProductService.products;
}
let productDisplayLength = productDisplay.length;
if(this.pageNumber == 0) {
this.startDisplay = 0;
this.endDisplay = this.PRODUCTS_PER_PAGE/2;
this.previousPage = 'disabled';
for(let i=this.startDisplay; i <this.endDisplay; i++) {
this.products.push(productDisplay[i]);
}
let nextColumn = this.endDisplay + this.PRODUCTS_PER_PAGE/2;
for(let i=this.endDisplay; i<nextColumn; i++){
this.productsNextColumn.push(productDisplay[i]);
}
}
//Click on other pages..
else {
this.previousPage = '';
this.startDisplay = this.pageNumber * this.PRODUCTS_PER_PAGE;
this.endDisplay = this.startDisplay + this.PRODUCTS_PER_PAGE/2;
if(productDisplayLength > this.endDisplay) {
for(let i=this.startDisplay; i <this.endDisplay; i++)
this.products.push(productDisplay[i]);
let nextColumn = this.endDisplay + this.PRODUCTS_PER_PAGE/2;
if(productDisplayLength >= nextColumn) {
for(let i=this.endDisplay; i<nextColumn; i++)
this.productsNextColumn.push(productDisplay[i]);
if(productDisplayLength > nextColumn)
this.nextPage = '';
else
this.nextPage = 'disabled';
} else {
for(let i=this.endDisplay; i<productDisplayLength; i++){
this.productsNextColumn.push(productDisplay[i]);
}
this.nextPage = 'disabled';
}
} else {
for(let i=this.startDisplay; i <productDisplayLength; i++)
this.products.push(productDisplay[i]);
}
}
if(this.advertisements[this.pageNumber] != null)
this.advertisement = this.advertisements[this.pageNumber];
}
One application design pattern that many data driven applications use is server side pagination. Basically the server sends a subset of data to the client AKA a "page", and the client requests for additional pages when needed. Here is an angularJS example using server side pagination https://ciphertrick.com/2015/08/31/server-side-pagination-in-angularjs
I have been playing around with this script for the last couple weeks. The goal of the script is to go through a reporting inbox, pull reporting data from email attachments, copy into a google spreadsheet, and then relabel the emails to remove them from the inbox to prevent accidental double copying reports.
The script functions in this order:
Look for new emails in the Inbox with attachments
Copy attachment data
Paste into Spreadsheet in the next open row
Relabel the email with "Report" instead of "Inbox" to move all reports into a reporting folder
I have successfully accomplished steps 1 - 3, but for the life of me, I can not get the relabeling to work. When I run debug in the Google Apps console, it doesn't come back with any errors. Pasted below is the excerpt from the script doing the relabeling:
for (var i = 0; i < myLabel.length; i++) {
labels = myLabel[i].getLabels();
for (var j = 0; j < labels.length; j++) {
labels[j].addLabel("test_2");
labels[j].removeLabel("Test");
}
}
Below is the full script I am running.
function getCSV() {
// Create variable that looks for Gmails in the main inbox
var myLabel = GmailApp.getUserLabelByName("test");
Logger.log("myLabel:",myLabel);
// Create variable that is filled with all threads within Inbox label
var threads = myLabel.getThreads();
Logger.log("threads:",threads);
// Retrieves all messages in the specified thread
var msgs = GmailApp.getMessagesForThreads(threads);
Logger.log("msgs:",msgs);
// Uses active sheet the script is implemented on
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("test");
// Grabs CSV data from attachments and pastes into next available row in Spreadsheet
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var attachments = messages[j].getAttachments();
Logger.log("attachments:",attachments);
var csvData = Utilities.parseCsv(attachments[j].getDataAsString(), ",");
Logger.log(csvData);
for (var k = 1; k < csvData.length; k++) {
var dataPaste = sheet.appendRow(csvData[k]);
Logger.dataPaste;
}
}
}
// Removes Inbox Label and Adds Report Label
for (var i = 0; i < myLabel.length; i++) {
labels = myLabel[i].getLabels();
for (var j = 0; j < labels.length; j++) {
labels[j].addLabel("test_2");
labels[j].removeLabel("Test");
}
}
}
I ended up figuring this out. In addition, I added a section that can pull data if the CSVs are zipped.
function getCSV() {
// Associated Inbox label and Report Label with variables
var myInboxLabel = GmailApp.getUserLabelByName("Test");
var myReportLabel = GmailApp.getUserLabelByName("test_2");
// Create variable that is filled with all threads within Inbox label
var threads = myInboxLabel.getThreads();
Logger.log("threads:" + threads);
// Retrieves all messages in the specified thread
var msgs = GmailApp.getMessagesForThreads(threads);
Logger.log("msgs:" + msgs);
// Uses active sheet the script is implemented on
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("test");
/* Script to pull data from CSV that is NOT zipped
// Grabs CSV data from attachments and pastes into next available row in Spreadsheet
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var attachments = messages[j].getAttachments();
Logger.log("attachments:" + attachments);
var csvData = Utilities.parseCsv(attachments[j].getDataAsString(), ",");
Logger.log("csvData:" + csvData);
for (var k = 1; k < csvData.length; k++) {
var dataPaste = sheet.appendRow(csvData[k]);
Logger.dataPaste;
}
}
}
*/
// Grabs CSV within a zip folder and pastes into next available row in Spreadsheet
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var attachments = messages[j].getAttachments();
var extracted = Utilities.unzip(attachments[j]);
var csvData = Utilities.parseCsv(extracted[j].getDataAsString(), ",");
Logger.log(csvData);
for (var k = 1; k < csvData.length; k++) {
var dataPaste = sheet.appendRow(csvData[k]);
Logger.dataPaste;
}
}
}
// Removes Inbox Label and Adds Report Label
for (var x in threads) {
var thread = threads[x];
thread.removeLabel(myInboxLabel);
thread.addLabel(myReportLabel);
}
}
I am having an issue with a script. I used the following script from Google Developers Website in order to do a simple merge mail. See https://developers.google.com/apps-script/articles/mail_merge
I modified a bit the script so to prevent email duplicates. However, even if the script seems to work as it marks 'EMAIL_SENT' in each row every time an email is sent. It does not pay attention if the mail as already been marked and still send the mail.
I believe there is an error at line 16 "var emailSent = rowData[6];"
I would really appreciate if someone could help me. Whoever you are thanks in advance.
Here is the modified script :
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getSheets()[0];
var dataRange = dataSheet.getRange(2, 1, dataSheet.getMaxRows() - 1, 7);
var templateSheet = ss.getSheets()[1];
var emailTemplate = templateSheet.getRange("A2").getValue();
var objects = getRowsData(dataSheet, dataRange);
for (var i = 0; i < objects.length; ++i) {
var Resume = DriveApp.getFilesByName('Resume.pdf') var Portfolio = DriveApp.getFilesByName('Portfolio.pdf') var rowData = objects[i];
var emailText = fillInTemplateFromObject(emailTemplate, rowData);
var emailSubject = "Architectural Internship";
var emailSent = rowData[6];
if (emailSent != EMAIL_SENT) {
MailApp.sendEmail(rowData.emailAddress, emailSubject, emailText, {
attachments: [Resume.next(), Portfolio.next()]
});
dataSheet.getRange(2 + i, 7).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
function fillInTemplateFromObject(template, data) {
var email = template;
var templateVars = template.match(/\${\"[^\"]+\"}/g);
for (var i = 0; i < templateVars.length; ++i) {
var variableData = data[normalizeHeader(templateVars[i])];
email = email.replace(templateVars[i], variableData || "");
}
return email;
}
function getRowsData(sheet, range, columnHeadersRowIndex) {
columnHeadersRowIndex = columnHeadersRowIndex || range.getRowIndex() - 1;
var numColumns = range.getEndColumn() - range.getColumn() + 1;
var headersRange = sheet.getRange(columnHeadersRowIndex, range.getColumn(), 1, numColumns);
var headers = headersRange.getValues()[0];
return getObjects(range.getValues(), normalizeHeaders(headers));
}
function getObjects(data, keys) {
var objects = [];
for (var i = 0; i < data.length; ++i) {
var object = {};
var hasData = false;
for (var j = 0; j < data[i].length; ++j) {
var cellData = data[i][j];
if (isCellEmpty(cellData)) {
continue;
}
object[keys[j]] = cellData;
hasData = true;
}
if (hasData) {
objects.push(object);
}
}
return objects;
}
function normalizeHeaders(headers) {
var keys = [];
for (var i = 0; i < headers.length; ++i) {
var key = normalizeHeader(headers[i]);
if (key.length > 0) {
keys.push(key);
}
}
return keys;
}
function normalizeHeader(header) {
var key = "";
var upperCase = false;
for (var i = 0; i < header.length; ++i) {
var letter = header[i];
if (letter == " " && key.length > 0) {
upperCase = true;
continue;
}
if (!isAlnum(letter)) {
continue;
}
if (key.length == 0 && isDigit(letter)) {
continue;
}
if (upperCase) {
upperCase = false;
key += letter.toUpperCase();
} else {
key += letter.toLowerCase();
}
}
return key;
}
// Returns true if the cell where cellData was read from is empty. // Arguments: // - cellData: string function isCellEmpty(cellData) {
return typeof(cellData) == "string" && cellData == "";
}
// Returns true if the character char is alphabetical, false otherwise. function isAlnum(char) { return char >= 'A' && char <= 'Z' || char >= 'a' && char <= 'z' || isDigit(char); }
// Returns true if the character char is a digit, false otherwise. function isDigit(char) { return char >= '0' && char <= '9'; }
Your code is really hard to read and the functions that return 2 or more objects make it even harder...you are using variable names that are also a bit confusing.... but that is probably a personal pov :-)
Anyway, I think I've found the issue: when you write var rowData = objects[i];
This "object" is actually the result of the getRowData function but if you look at this function, you'll see that it returns 2 objects, the first one being itself the result of another function (getObjects) ...
You are checking the value is the 6th element of the array which is actually an object and compare it to a string. The equality will never be true.
I didn't go further in the analyse since I found it really confusing ( as I already said) but at least you have a first element to check .
I would suggest you rewrite this code in a more simple way and use more appropriate variable names to help you while debugging.
I would recommend logging both values before executing to make sure they are the same. I would also guess that the email_sent and EMAIL_SENT are different data types. Can also try forcing the value to string for comparison.
To clarify:
logger.Log(emailSent);
logger.Log(EMAIL_SENT);
if (emailSent.toString() != EMAIL_SENT.toString())
{...
Error is in this line of code -
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
It's considering only 2 columns in the range. Changed 2 to 3 and it worked fine.