In my angular controller i have ExportToExcel function, which is using alasql to export data to Excel and the data is coming from angular array.
The issue is the array might contains null as data, is it a way to replace null to empty string in alasql
Following is the function
ac.ExportToExcel = function () {
var time = new Date().toJSON().slice(0, 10);
alasql('SELECT * INTO XLSX("ExchangeReport' + time + '.xlsx",{headers:true}) FROM ? WHERE BillingPeriod = "' + ac.ExchangeReport.BillingPeriod + '" or "' + ac.ExchangeReport.BillingPeriod + '" = "" ', [ac.ExchangeDatas]);
}
And this is my data source
ac.ExchangeDatas = [];
from
ac.GetAllExchangeData = function () {
AccountRepository.GetAllExchangeData().$promise.then(
function (data) {
ac.ExchangeDatas = data.result;
},
function (err) {
console.log("error in GetAllExchangeData : " + err);
}
);
}
Data in excel:
var old = JSON.stringify($scope.achData).replace(/null/g, '""'); //convert to
JSON string and puts empty string in place of null values
var newArray = JSON.parse(old); //convert back to array
alasql('select * into XLSX("amar.xlsx", {headers:true}) from ?', [newArray]);
You should be able to use COALESCE, though you need to list all the columns like COALESCE(YourColumn,'') AS YourColumn instead of *. See https://github.com/agershun/alasql/wiki/Coalesce
Related
I am trying to use textFinder to return the data from recordsSheet; I expect cslData[0] to return the employee ID number; however, it is returning the character in the 0 position of the string value.
function textFinder(findID){
var recordData;
var findRecord = recordsSheet.createTextFinder(findID);
var foundRange = findRecord.findNext();
var fRng = recordsSheet.getRange(foundRange.getRow(),1,1,9)
while(null != foundRange){
recordData.push(fRng.getValues());
foundRange = findRecord.findNext();
}
return(recordData);
}
var ss = SpreadsheetApp.getActiveSpreadsheet();
var recordsSheet = ss.getSheetByName("Active Records");
function onFormSubmit(e) {
var eRng = e.range;
var eRow = eRng.getRow();
var colA = ss.getRange('A' + eRow).getValue()
//The second value of the form response (e) is in Column A
Logger.log("Call txt finder")
var cslData = textFinder(colA).toString().split(",").join();
Logger.log("cslData: " + cslData)
Logger.log("cslData[0]: " + cslData[0])
Logger.log("cslData[1]: " + cslData[1])
Logger.log("cslData[2]: " + cslData[2])
Logger.log("cslData[0][0]: " + cslData[0][0])
}
I was expecting cslData[0] to return "100###5"
Modification points:
In your script, eRow is not declared. And, e is not used. Please be careful about this. In this modification, it supposes that eRow is declared elsewhere.
In your script, var recordData; is not an array. So, I think that an error occurs at recordData.push(fRng.getValues());. So, I'm worried that your showing script might be different from your tested script.
If var recordData; is var recordData; = [], about your current issue, in your script, the array of recordData is converted to the string by var cslData = textFinder(colA).toString().split(",").join();. By this, cslData[0] returns the top character. I thought that this is the reason for your issue.
And, if var recordData; is var recordData; = [], recordData is 3 dimensional array.
In your situation, I thought that findAll might be useful.
When these points are reflected in your script, how about the following modification?
Modified script:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var recordsSheet = ss.getSheetByName("Active Records");
function textFinder(findID) {
return recordsSheet
.createTextFinder(findID)
.findAll()
.map(r => recordsSheet.getRange(r.getRow(), 1, 1, 9).getValues()[0]);
}
function onFormSubmit(e) {
var colA = ss.getRange('A' + eRow).getValue();
var cslData = textFinder(colA);
Logger.log("cslData: " + cslData);
if (cslData.length > 0) Logger.log("cslData[0]: " + cslData[0][0]);
}
or, I think that you can also the following script.
function onFormSubmit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var recordsSheet = ss.getSheetByName("Active Records");
var eRow = ###; // Please set this.
var findID = ss.getRange('A' + eRow).getValue();
var cslData = recordsSheet.createTextFinder(findID).findAll().map(r => recordsSheet.getRange(r.getRow(), 1, 1, 9).getValues()[0]);
Logger.log("cslData: " + cslData)
if (cslData.length > 0) Logger.log("cslData[0]: " + cslData[0][0])
}
Reference:
findAll()
I need to execute a function inside ng-repeat to convert date. How can i parse a angular result in a function?
Field name in database is dataf
I tried diferent ways but no one works...
<tr ng-repeat="detail in details| filter:search_query">
<td><b>{{detail.nom}}</b></td>
<td>{{detail.descripcio}}</td>
<td>{{datareves(detail.datafet) }} </td>
<td>{{detail.visible}}</td>
and
getInfo();
function getInfo(){
$http.post('empDetails.php').success(function(data){
$scope.details = data;
});
}
$scope.datareves = function(details.datafet) {
var res = dataf.split(" ");
var res2 = res[0].split("-");
var final = res2[2] + "-" + res2[1] + "-" + res2[0];
return (final);
};
Your function should look like this
$scope.datareves = function(dataf) {
var res = dataf.split(" ");
var res2 = res[0].split("-");
var final = res2[2] + "-" + res2[1] + "-" + res2[0];
return (final);
};
notice the change to the first line. The name of the variable you used in the function was not the same as the name being passed into the function.
You can read more about javascript function definitions here https://www.w3schools.com/js/js_function_definition.asp
I'm trying to make request link from input field to backend. My entity set is called ActionsSet, property of entity set is Applctn. I want to pass parameter from input field with Filter operator EQ. I can't figure out the proper way. Here is my code snippet.
onPress: function() {
var oParameter = this.getView().byId("inp").getValue();
if (oParameter == '') {
var msg = 'Fill it!';
MessageToast.show(msg);}
else{
var oModel = new sap.ui.model.odata.v2.ODataModel("<SERVERURL>/sap/opu/odata/sap/ZACTIONS_SRV/ActionsSet?$filter = Applctn eq '" + oParameter + "'");
}
Allright so I made it more simple. But I have this error 400 Bad request as
/ZACTIONS_SRV/ActionsSet/$metadata?$filter%20=%20Applctn%20eq%20%27kjh%27
Maybe problem is that request is in this format
Screen
And I guess I need that is this format to pass filter so backend, because this filter works in another app Screen
I found solution, here is the right way how to post query to OData service:
onPress: function() {
var oParameter = this.getView().byId("inp").getValue();
if (oParameter == '') {
var msg = 'Fill it!';
MessageToast.show(msg);}
else{
var oModel = new sap.ui.model.odata.ODataModel("<SERVERURL>/sap/opu/odata/sap/ZACTIONS_SRV/");
var Filter = new sap.ui.model.Filter('Applctn', 'EQ', oParameter);
oModel.read("/ActionsSet", {
filters: [Filter]
});
}
Your serviceUrl will be :
serviceUrl: "http://consap2.consit.local:8060/sap/opu/odata/sap/ZACTIONS_SRV/ActionsSet?$filter = Applctn eq '" + oParameter + "'"
oParameter should be specified in single quotes as serviceUrl is enclosed within " "
I am using Parse for my app. I have two tables StudentDetail and Subject,as user enters his name, the id is queried from studentDetail table. and using that id i want to fetch rest of the details of Subject table.Data fetched through this code is correct but in $scope.subs i.e 19th line it overrides the data and returns only the last record,i want to store all the records in $scope.subs object iteratively.
$scope.subjectFetch= function(form,form1) {
var query = new Parse.Query(StudentDetail);
var querySub = new Parse.Query(Subject);
query.equalTo("Firstname",form1.Firstname);
query.find({
success: function(results) {
stdId = results[0].id;
querySub.equalTo("StudentId",stdId);
querySub.find({
success: function(subjects) {
alert("Success");
for (var i = 0; i < subjects.length; i++) {
var object = subjects[i];
subname = object.get('Name');
credits = object.get('credits');
code =object.get('code');
duration = object.get('duration');
alert("Subject name: "+subname+"\n Credits :"+credits+"\n Code :"+code+"\n Duration:"+duration);
$scope.subs=[{Name:subname,credits:credits,code:code,duration:duration},{Name:"xyz",credits:5}];
//console.log($scope.subs);
}
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
}
You are setting $scope.subs to be a new array with a single object in it inside your loop, which is why only the last one is there when it is done.
Try the following success handler instead:
success: function(subjects) {
// reset subs array
$scope.subs = [];
for (var i in subjects) {
var subject = subjects[i];
// push new object into the array
$scope.subs.push({
Name: subject.get('Name'),
credits: subject.get('credits'),
code: subject.get('code'),
duration: subject.get('duration')
});
}
// log the populated array
console.log($scope.subs);
Alternatively if you use something like the Underscore library, you can just map the items:
// replace success function body with this:
$scope.subs = _.map(subjects, function(subject) {
return {
Name: subject.get('Name'),
credits: subject.get('credits'),
code: subject.get('code'),
duration: subject.get('duration')
};
});
console.log($scope.subs);
I am pretty new to node.js
For my application, I am currently fetching a set of rows using the code below and iterate over each row for value of a particular column...
query = 'select ' + colName +
' from ' + rows[0].tablename +
' where ' +
'dictionaryid=' + rows[0].dictionaryid +
' and id between ' + lower + ' and ' + upper;
connection.query(query, function(err, rows1, fields) {
if (err) {
console.log(err);
throw err;
}
var contents = [];
rows1.forEach(function(elem) {
for (var key in elem) {
if (key == colName) {
contents.push(elem[key]);
}
}
});
So, in the code above, I fetch a set of rows in rows1 and iterate over all of them using a forEach.
What I want to do it to access something like rows1[i][key] i.e like 3rd column of 4th row.
How do I do it.
Any help is appreciated.
Thanks.
You could use underscore toArray to do something like this:
var _ = require('underscore');
var contents = [];
rows1.forEach(function(elem) {
contents.push(_.toArray(elem));
});
var someValue = contents[3][2]; //3rd column of 4th row.