I am programming something in SAPUI5 with an oData model.
I need to get this value:
Which is declared in my view as Orgpf:
<HBox class="sapUiResponsiveMargin">
<Text class="titulo" id="tituloplanta" text="{i18n>tituloTablaPl} "/>
<Text class="titulo" id="planta" text="{Orgpf}"/>
</HBox>
When i check "Console" tab in Chrome, i get this:
Where mProperties has the text value i need.
So I tried to get that value writing this on my controller:
var a = this.getView().byId("planta").bindElement({
path: "/CenTVSet('" + ip + "')"
});
var oModel = this.getView().getModel();
var planta = oModel.oData;
value = this.byId("planta").getText();
But it doesn't show anything in console and shows this error pointing my code:
Is there any way to get through this and get that value from the controller?
Edit:
Trying to use value = this.byId("planta").getText();
It shows in the console but as an empty value:
You should use the provided API to get the value from text property.
const value = this.byId("planta").getText();
With this you can work with the controls text value inside your controller.
Here is the solution I got, to get that value:
oModel.read("/CenTVSet('" + ip + "')",{
success: function(oData, oRes){
var einri = oData.Einri;
var orgpf = oData.Orgpf;
var oTable = that.getView().byId("tablaPacientes");
var oBinding = oTable.getBinding("items");
var filter = new Filter({
path: "Orgna",
operator: FilterOperator.EQ,
value1: orgpf
});
oBinding.filter(filter);
//numero de pacientes
oBinding.attachDataReceived(function(oEvent){
var iLength = oEvent.getSource().getLength();
var oViewModel = new JSONModel({npat: iLength});
that.getView().setModel(oViewModel, "view");
// that.getView().byId("pat").setText(iLength);
});
},
error: function(oError){
console.log("Error");
}
});
Related
I'm attempting to run the following code which is pretty much copied from the OoTheBox UI Action called "View User's Response".
function showRiskAssessment(){
var ra = new GlideRecord('asmt_assessment_instance');
ra.addQuery('task_id', '=', current.sys_id);
ra.orderByDesc('taken_on');
ra.setLimit(1);
ra.query();
// var id = g_form.getUniqueValue();
var id = ra.sys_id;
//var type = g_form.getValue('metric_type');
var type = '468aeff2db9357008aeba9f7059619ca';
var url = 'assessment_take2.do?sysparm_assessable_sysid=' + id + '&sysparm_assessable_type=' + type + '&sysparm_reader_view=true';
var d = new GlideOverlay({
title: "User's Response",
iframe: url,
width:'80%',
height: '100%',
onAfterLoad: function() {
var iframe = d.getIFrameElement();
setTimeout(function(){
iframe.height = parseInt(iframe.height)+1;
},0);
}
});
d.render();
}
If I hardcode it like this it works. All I'm trying to do is on the change record I want to look up the most recent Assessment Instance for that particular change and display in the overlay. Obviously I can't hardcode the id however it seems the query isn't recognizing that info at all anyways.
function showRiskAssessment(){
// var ra = new GlideRecord('asmt_assessment_instance');
// ra.addQuery('task_id', '=', current.sys_id);
// ra.orderByDesc('taken_on');
// ra.setLimit(1);
// ra.query();
// var id = g_form.getUniqueValue();
var id = '5c516eeddb87d090ebce60ab1396198a';
//var type = g_form.getValue('metric_type');
var type = '468aeff2db9357008aeba9f7059619ca';
var url = 'assessment_take2.do?sysparm_assessable_sysid=' + id + '&sysparm_assessable_type=' + type + '&sysparm_reader_view=true';
var d = new GlideOverlay({
title: "User's Response",
iframe: url,
width:'80%',
height: '100%',
onAfterLoad: function() {
var iframe = d.getIFrameElement();
setTimeout(function(){
iframe.height = parseInt(iframe.height)+1;
},0);
}
});
d.render();
}
You're trying to use current.sys_id in a client side script. It is recommended to use g_form for client side scripts. You're also trying a GlideRecord on a client script, which is also not recommended.
To fix, replace:
ra.addQuery('task_id', '=', current.sys_id);
with:
var sysId = g_form.getUniqueValue();
ra.addQuery('task_id', '=', sysId);
Also, for the difference between g_form and current have a look here.
I have a codeigniter service that returns this:
{data: ["CEDULA-1723822761.pdf", "CROQUIS-1723822761.pdf", "PENSION-1723822761.pdf"], success: "true"}
And on my ExtJS App I'm trying to process it like this:
var responseData = opts.result.data;
var documentos = Ext.ComponentQuery.query("#docsTest")[0];
documentos.setValue(responseData); //This is just to check that the data is correct
var store = new Ext.data.SimpleStore({
fields:[
{name: 'name'}//I'm pretty sure my problem is here
]
});
store.loadData(responseData);
console.log('store:' + store);
var grid = Ext.ComponentQuery.query("#FldDocumentos")[0];
grid.setStore(store);
I want to show each one of the three results given by the service in a row in the grid but since the array doesn't specify a field name, the store just creates three empty objects. How can I correctly store each of the array strings in the store?
Create an Array and store the data with name attribute. So when you add this to store, grid can display data correctly.
var responseData = opts.result.data;
var documentos = Ext.ComponentQuery.query("#docsTest")[0];
documentos.setValue(responseData); //This is just to check that the data is correct
var store = new Ext.data.SimpleStore({
fields:[
{name: 'name'}//I'm pretty sure my problem is here
]
});
var nameList = [];
for(var i = 0 ; i < responseData.length ; i++){
nameList.push({ name = responseData[i]});
}
store.loadData(nameList);
console.log('store:' + store);
var grid = Ext.ComponentQuery.query("#FldDocumentos")[0];
grid.setStore(store);
I have a product catalog made with CustomTile Control. When I press one tile, I want to go to a details page. For that I need to know some of the values that are on the pressed tile, which I'm not able to.
Here is the code for the tile and the binding:
var sServiceUrl = "/sap/opu/odata/sap/ztestefardas_srv/"; //URL do serviço oDATA
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl);
sap.ui.getCore().setModel(oModel);
OData.read("/sap/opu/odata/sap/ztestefardas_srv/catalogo",
function (response){
for(var key in response.results) {
var value = response.results[key];
var oImg =new sap.ui.commons.Image({
width :"160px",
height :"160px"
}).setSrc(value["img"]);
oImg.addStyleClass("img_cat");
var oMatxt =new sap.ui.commons.TextView({
text: value["matxt"],
width: "200px"
}).addStyleClass("matxt");
var oAtr =new sap.ui.commons.TextView({
text: "Atribuídos: "+value["n_atr"],
width: "200px"
}).addStyleClass("second_line");
if (value["n_dis"] > 0){
var oDis =new sap.ui.commons.TextView({
text: "Disponíveis: "+value["n_dis"],
width: "200px"
}).addStyleClass("second_line_disp");
} else {
var oDis =new sap.ui.commons.TextView({
text: "Disponíveis: "+value["n_dis"],
width: "200px"
}).addStyleClass("second_line");
}
var oPtxt =new sap.ui.commons.TextView({
text: "Próximo levantamento:",
width: "200px"
}).addStyleClass("third_line");
var oPlev =new sap.ui.commons.TextView({
text: value["p_lev"],
width: "200px"
}).addStyleClass("third_line");
var oLayout = new sap.ui.commons.layout.VerticalLayout({
content: [oImg,oMatxt,oAtr,oDis,oPtxt,oPlev]
});
var oTile = new sap.m.CustomTile({
content:oLayout,
press: function(oEvento){
//missing code to get values from selected tile
oNavContainer.to(Page2);
}
}).addStyleClass('sapMTile');
oContainer.addTile(oTile);
}});
I've tried with the table attach row selection change way, but it's not working too.
Can you please help?
Thank you.
Add the following code in your function (response) method:
var valueModel = new sap.ui.model.json.JSONModel({
"Value": "##your value here##",
});
oLayout.setModel(valueModel);
Add the following code in the press function handler:
var oLayout = oEvento.getSource().getContent();
var value = oLayout .getModel().getProperty("/Value");
Then you can get values from the CustomTile by using data binding to get the value your want.
Hope it helps.
I found a way to make this work.
within the FOR that I used to read the data from the odata:
oTile.data("matnr", value["Matnr"]);
oTile.data("matxt", value["Itmfdx"]);
oTile.data("n_dis", value["n_dis"]);
oTile.data("n_atr", value["n_atr"]);
oTile.data("endda", value["Endda"]);
oTile.data("itmfd", value["Itmfd"]);
these value["xpto"] are the keys from the response results (OData.read("/sap/opu/odata/sap/zmm_fardamentos_srv/CatalogoSet?sap-ui-language=PT",
function (response){
for(var key in response.results) {
var value = response.results[key];)
Then, I created a function for the attachPress event of oTile with these:
oTile.attachPress( function(){
sap.ui.getCore().getControl("selimg").setSrc(this.data("img"));
sap.ui.getCore().getControl("bigpic").setSrc(this.data("img"));
sap.ui.getCore().getControl("nome_material").setText(this.data("matxt"));
sap.ui.getCore().getControl("itmfd_var").setText(this.data("itmfd"));
sap.ui.getCore().getControl("atr_det").setText(this.data("n_atr"));
sap.ui.getCore().getControl("disp_det").setText(this.data("n_dis"));
sap.ui.getCore().getControl("lev_data").setText(this.data("endda"));
the names within getControl are the id of the variables that will hold the values.
Maybe this is not the fanciest way, but it sure works :)
In the following code, I need to pass the text variable from app.js to app_flip.js and display it over there. How can I do this ?
**In app.js**
var win = Titanium.UI.createWindow({backgroundColor:'white'});
button.addEventListener('click,function(e){
Ti.include('app_flip.js');
});
var text = Ti.UI.createLabel({ text:"hello" });
win.add(text);
**In app_flip.js**
var win = Titanium.UI.createWindow({backgroundColor:'white'});
You can open a new window using the following method
app.js
button.addEventListener('click', function(e){
var win = Ti.UI.createWindow({
url : 'app_flip.js',
backgroundColor : 'white',
_customProperty : 'Value of the property'
});
win.open();
});
app_flip.js
var win = Ti.UI.currentWindow;
var _customProperty = win._customProperty;
alert(_customProperty); //Will display Value of the property
You can use this as a reference
Hello friends,
I am developing an app using Google Place API in Titanium Development and successfully got data and display in tableview and add button in each row but my issue is that I want to get name and address on button click in each row so please give me idea or any link to solve my issue.
Please take a look in my screenshot so on btnclick I want to get name and address.
Thanks in advance.
var categoryName;
var addressLabel;
var row;
var tableData=[];
PlacesListCells = function createRow()
{
//var tableData=[];
var loader = Titanium.Network.createHTTPClient();
var url = "https://maps.googleapis.com/maps/api/place/search/json?";
url = url + "location=" + lat + ',' + lon;
url = url + "&radius=" + radius;
url = url + "&name=" + name;
url = url + "&sensor=" + sensor;
url = url + "&key=" + key;
Ti.API.info(url);
// Sets the HTTP request method, and the URL to get data from
loader.open("GET",url);
// Create our HTTP Client and name it "loader"
// Runs the function when the data is ready for us to process
loader.onload = function()
{
var obj = JSON.parse(this.responseText);
Ti.API.log(obj);
var results = obj.results;
Ti.API.log(results);
for (var i = 0; i < results.length; i++)
{
categoryName = obj.results[i].name;
reference = obj.results[i].reference;
Ti.API.log('Refernce:'+reference);
// Create a row and set its height to auto
row = Titanium.UI.createTableViewRow({height:'78'});
var placeImage = Titanium.UI.createImageView
({
image:'../iphone/appicon.png',
width:70,
height:50,
top:12,
left:5
});
// Create the label to hold the tweet message
var nameLabel = Titanium.UI.createLabel({
//text:name,
left:80,
top:5,
height:'auto',
width:185,
textAlign:'left',
font:{fontSize:12}
});
// Create the label to hold the tweet message
addressLabel = Titanium.UI.createLabel({
left:80,
top:25,
height:'auto',
width:185,
textAlign:'left',
font:{fontSize:14}
});
var arrowImage = Ti.UI.createImageView
({
image:'../iphone/appicon.png',
width:20,
height:20,
left:280,
top:30
});
var favoriteButton = Ti.UI.createButton
({
title:'btn',
//font:{fontFamily:'Helvetica Neue',fontSize:15},
top:20,
left:255,
height:30,
width:50,
url:'../Images/favorite.png'
//image:'../Images/favorite.png'
});
nameLabel.text = categoryName;
getDetailsData(addressLabel,row,i);
row.add(placeImage);
row.add(nameLabel);
row.add(addressLabel);
row.add(favoriteButton);
//row.add(arrowImage);
tableData[i] = row;
//set page title for each row
row.pageTitle = nameLabel.text;
favoriteButton.row = i;
favoriteButton.addEventListener('click', function(e)
{
Ti.API.log('favoriteButton clicked on row ' + e.source.row +' at ' + new Date().getSeconds());
alert('favoriteButton clicked on row ' + e.source.row);
var index = e.source.row;
var name = tableData[index];
alert('name'+name);
});
}
tableView.setData(tableData);
};
//-- Network error
loader.onerror = function(e)
{
Ti.API.info('Network error: ' + JSON.stringify(e));
};
// Send the HTTP request
loader.send();
return tableData;
};
Once you have your index, you should be able to reference your original data source by that.
var favoriteButton = Ti.UI.createButton({
title:'btn',
//font:{fontFamily:'Helvetica Neue',fontSize:15},
top:20,
left:255,
height:30,
width:50,
url:'../Images/favorite.png'
//image:'../Images/favorite.png',
name:categoryName,
address:address;//address mention here
});
row.add(favoriteButton);
favoriteButton.addEventListener('click', function(e)
{
var index = e.source.row;
var name = e.source.name;
var address = e.source.address;
alert('name'+name);
});
}
I think this might help you a lot.