on 11-14-2018 9:23 AM
I wish to call a function currentStock, in po approval standard application after the item details screen as been loaded. since I'm using parameters from that screen as filters in a odata service which is called in that fuction.
where am I going wrong how do I do that???
this is where I'm trying right now.
function()
currentStock: function () {
debugger;
var matId = this.getView().byId("matId").getText();
var plantId = this.getView().byId("plantId").getText();
var that = this;
var oItemDetailsInfoCurrentStock = this.getView().byId("ItemDetailsInfoCurrentStock");
if (matId != "" && plantId != "") {
var sServiceUrl = "/sap/opu/odata/AAG362/MM_PURCHASE_APPROVAL_SRV";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
oModel.setUseBatch(false);
var currentStock = "/CurrentStockSet?$filter=Material eq '" + matId + "' and Plant eq '" + plantId + "'";
oModel.read(currentStock, {
success: function (oData, response) {
if (oData.results !== "undefined" || oData.results !== null) {
var oJModel = new sap.ui.model.json.JSONModel();
oJModel.setData(oData.results);
that.getView().setModel(oJModel, "cStk");
that.getView().byId("txtCStk").setText(oData.results[0].CurrentStk);
}
},
error: function (error) {
var message = "Error";
sap.m.MessageBox.show(message, sap.m.MessageBox.Icon.ERROR, "Error");
}
});
oItemDetailsInfoCurrentStock.setVisible(true);
} else {
oItemDetailsInfoCurrentStock.setVisible(false);
}
},
/////////////////////////////////////////////////////////
oninit()
onInit: function () {
this.getView().getModel().setSizeLimit(1000000);
if (!this.oApplication) {
this.oApplication = sap.ca.scfld.md.app.Application.getImpl();
this.oConfiguration = this.oApplication.oConfiguration;
this.oConnectionManager = this.oApplication.getConnectionManager();
this.resourceBundle = this.oApplication.getResourceBundle();
this.oDataModel = this.oApplicationFacade.getODataModel
}
this.oRouter.attachRouteMatched(function (e) {
if (e.getParameter("name") === "itemDetails") {
this.currentStock(); // here
this.vendorCompare(); //here
this.sOrigin = e.getParameter("arguments").SAP__Origin;
this.sWorkitemID = e.getParameter("arguments").WorkitemID;
this.sPoNumber = e.getParameter("arguments").PoNumber;
this.sItemNumber = e.getParameter("arguments").ItemNumber;
var i = "/WorkflowTaskCollection(SAP__Origin='" + this.sOrigin + "',WorkitemID='" + this.sWorkitemID + "')" +
"/HeaderDetails/ItemDetails(SAP__Origin='" + this.sOrigin + "',PoNumber='" + this.sPoNumber + "',ItemNumber='" + this.sItemNumber +
"')";
var I = "/ItemDetailCollection(SAP__Origin='" + this.sOrigin + "',ItemNumber='" + this.sItemNumber + "',PoNumber='" + this.sPoNumber +
"')";
var o = this.oDataModel.getProperty(I);
var s = "";
if (o) {
s = o.ItemCategory;
}
var S = this.byId("SubcontractingTable");
if (s === "3") {
this.getView().bindElement(i, {
expand: "Accountings,Notes,PricingConditions,Attachments,ServiceLines/Accountings,Limits/Accountings,Components"
});
this.getView().getElementBinding().attachEventOnce("dataReceived", function () {
var c = [
new sap.m.ObjectIdentifier({
title: "{parts:[{path : 'Description'}, {path : 'Material'}], formatter : 'ui.s2p.mm.purchorder.approve.util.Conversions.IDFormatter'}"
}),
new sap.m.ObjectNumber({
number: "{parts: [{path : 'Quantity'}], formatter : 'ui.s2p.mm.purchorder.approve.util.Conversions.formatQuantityWithoutUnit'}",
numberUnit: "{BaseUnitDescription}"
})
];
var t = new sap.m.ColumnListItem({
cells: c
});
S.bindItems("Components", t, null, null);
S.setVisible(true);
}, this);
} else {
this.getView().bindElement(i, {
expand: "Accountings,Notes,PricingConditions,Attachments,ServiceLines/Accountings,Limits/Accountings"
});
S.setVisible(false);
}
this.setLocalHeaderFooterOptions();
}
}, this);
if (this.extHookOnInit) {
this.extHookOnInit();
}
this.currentStock(); //here
this.vendorCompare(); //here
},
Hi Siddharth,
I think what you are looking for is not when the screen is loaded but when the data is loaded in the detail screen.. hope I am right here..why I am saying this is that you are trying to read the material and plant data which will obviously be set to those UI elements only once the data is loaded..
Then you need to check if the request in the detail screen is successful or not. If it is successful then you need to call your piece of code..
For e.g., assuming that it is a standard application, SAP might be doing an element binding to the detail page, then here you need to register for that particular models 'requestedCompleted' event and here, check based on your condition if you can add your piece of code..
https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel/events/requestCompleted
BR,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As it is a standard app you are enhancing, I am assuming that might have set the odatamodel name to space ''. so you can do like this below:
this.getComponent().getModel().attachRequestCompleted( function(oEvent){
// Here oEvent will have your request details, verify and write your logic accordingly
}, this );
you should probably do the call in the onAfterRendering hook instead of the init as the view items probably still have no value in the init
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if you need to make a call after the screen has been loaded, then i echo Brian's comment that you need to do this on the onAfterRendering event.. however, if you need to use values from your screen, then you need to be invoking the function from a screen event such as a click or any other event that needs to be followed from.. what the issue may be is how you are using the this keyword... when you open the developer tools from the browser and debug your code.. make sure your this keyword refers to the actual object you are truly trying to use and not a different one... this is a recurring issue on developers... good luck!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.