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 );
Related
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"))
I have a datepicker that was created with the following code snippet:
return new sap.m.DatePicker(sId, {
dateValue: `{${sPath}}`,
valueFormat: "dd-MM-yyyy",
displayFormat: "dd-MM-yyyy"
});
Typing wrong weird stuff into the field:
It does not recognize the invalid format.
But when I tried to write in this example, it does recognize.
What am I doing wrong?
const oDatePicker = new DatePicker(sId).bindValue({
path: sPath,
type: new DateType({ // "sap/ui/model/type/Date"
pattern: "dd-MM-yyyy",
})
});
const messageManager = sap.ui.getCore().getMessageManager();
messageManager.registerObject(oDatePicker, true);
return oDataPicker;
If working with data binding, you'll need to bind the value property instead of dateValue.
API reference: sap.m.DatePicker
Use the value property if you want to bind the DatePicker to a model using the sap.ui.model.type.Date.
Use the dateValue property if the date is already provided as a JavaScript Date object or you want to work with a JavaScript Date object. (...) Although possible to bind it, the recommendation is not to do it. When binding is needed, use value property instead.
And finally, register the control to the MessageManager or enable handleValidation. UI5 will then take care of displaying the error message if the input could not be parsed or violates given constraints.
https://sapui5.hana.ondemand.com/#/sample/sap.m.sample.DatePicker/code/Group.controller.js
handleChange: function (oEvent) {
var oText = this.byId("T1");
var oDP = oEvent.oSource;
var sValue = oEvent.getParameter("value");
var bValid = oEvent.getParameter("valid");
this._iEvent++;
oText.setText("Change - Event " + this._iEvent + ": DatePicker " + oDP.getId() + ":" + sValue);
if (bValid) {
oDP.setValueState(sap.ui.core.ValueState.None);
} else {
oDP.setValueState(sap.ui.core.ValueState.Error);
}
}
this is the change handler used in the sample you have to implement the error handling by yourself
I am working on AngularJs application testing framework where I am using Protractor. I want to read the data (urls, usernames, passwords) from an excel sheet. I am using the following code but it's showing me errors.
Please find the below code:
var Excel = require('exceljs');
var wrkbook = new Excel.Workbook();
wrkbook.xlsx.readFile('E:\\Login_Data.xlsx').then(function()
{
var worksheet = wrkbook.getWorksheet('Sheet1');
worksheet.eachRow(function (Row, Test_URL)
{
console.log("Row " + Test_URL + " = " + JSON.stringify(Row.User_Name));
});
});
The data from excel sheet is :
Test_URL User_Name Password
http://...com abc#1111 xyz#333
Please let me know your positive inputs so that I can run my code and proceed forward.
Thanks in advance
eachRow isn't getting the Test_URL variable that you set as function parameter; that is instead the row index.
For getting every value of the row, you can use Row.values, and also you could the value of each Cell (corresponding to that row) with .getCell.
So it should be something like this:
var Excel = require('exceljs');
var wrkbook = new Excel.Workbook();
wrkbook.xlsx.readFile('E:\\Login_Data.xlsx').then(function()
{
var worksheet = wrkbook.getWorksheet('Sheet1');
worksheet.eachRow(function (Row, rowIndex)
{
var test_url = Row.getCell(1).value;
var user_name = Row.getCell(2).value;
var password = Row.getCell(3).value;
// do whatever you want with those variables.
});
});
I am using the using the sap webide. In my application I have some vizcharts binded to Odata. Now I am trying to download the vizcharts as PDF. But I am unable to get the value of vizcharts.
Below is my code from JS controller.
downloadClickHandler: function(oEvent) {var str = "width=500px,height=600px";
var wind = window.open("", "PrintWindow", str);
var chart = this.getView().byId("idVizFrameCountofTransactionUsed");
var Details = chart["sId"];wind.document.write(Details);
wind.print();
wind.close();
},
You can achieve it by:
_onDownload : function() {
var oVizFrame = this.byId("chartContainerVizFrame");
var oModel = oVizFrame.getModel();
var oData = oModel.oData;
}
In oData object now you have data from the chart. Please have a look in this example, and press download icon.
I have created SAPUI5 application, in that I have loaded data from external .xml file into a table, it was fine. Now, I am trying to delete a specific row from that table.
For this purpose, I use this code:
var oModel = new sap.ui.model.xml.XMLModel();
oModel.loadData("Deployments.xml", "", false);
sap.ui.getCore().setModel(oModel);
oTable.bindRows("/service"); // here "service" is the root element of xml file
var oTable = new sap.ui.commons.Button({
text: "Delete Service",
press: function() {
var idx = oTable.getSelectedIndex();
if (idx !== -1) {
var m = oTable.getModel();
var data = m.getData();
var removed = data.splice(idx, 1); // error showing at this line
m.setData(data);
sap.m.MessageToast.show(JSON.stringify(removed[0]) + 'is removed');
} else {
sap.m.MessageToast.show('Please select a row');
}
}
});
But, I am getting error at the line: var removed = data.splice(idx, 1);. However, the same code is good for when model is JSON. How can I delete a specific row from a table when model XMLModel?
It is a lot easier an more reliable to use a Bindings BindingPath to manipulate data belonging to a particular binding. Here is your adapted sample for a XMLModel:
press: function() {
var iIdx = oTable.getSelectedIndex();
var sPath = oTable.getContextByIndex(iIdx).getPath();
var oObj = oTable.getModel().getObject(sPath);
oObj.remove();
oTable.getModel().refresh();
}
This way you save the hazzle of dealing with the XML structure and furthermore this will scale with any change in the binding path you might introduce in the future.
BR
Chris
var data = m.getData();
data is not an Array. It is a XML document.
To remove an entry from the document:
var root = data.childNodes[0];
var aEntry = root.getElementsByTagName("entry");
root.removeChild(aEntry[idx]);