hello,
I am trying to create internal order using OData in Fiori.
I have currently used this code which is giving me errors saying Identifier Expected.
I'm using this blog as a reference :
XML
<Panel headerText="Internal Order Details" width="100%" height="auto" expanded="true" backgroundDesign="Solid">
<RadioButtonGroup id="group0" columns="2">
<buttons >
<RadioButton id="rbtnEUIB" text="IO Asset CAP Unbudgeted (EUIB)"/>
<RadioButton id="rbtnEIDB" text="IO Asset Budgeted Capex (EIBD)"/>
</buttons>
</RadioButtonGroup>
<HBox id="hbox1" width="100%" justifyContent="SpaceAround" wrap="Wrap" backgroundDesign="Solid">
<items>
<Input id="txtIONo" placeholder="Internal Order No"/>
<Input id="txtDesc" placeholder="Description"/>
</items>
</HBox>
</Panel>
<IconTabBar id="bar0" selectedKey="__xmlview0--attachment">
<items>
<IconTabFilter id="Info" text="Info" icon="sap-icon://hint" iconColor="Positive">
<content>
<sap.ui.layout.form:Form xmlns:sap.ui.layout.form="sap.ui.layout.form" id="form0" editable="true">
<sap.ui.layout.form:formContainers>
<sap.ui.layout.form:FormContainer id="container1">
<sap.ui.layout.form:formElements>
<sap.ui.layout.form:FormElement id="element1" label="Controlling Area">
<sap.ui.layout.form:fields>
<Input id="txtContolArea" value="4000" width="20%"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element2" label="Company Code">
<sap.ui.layout.form:fields>
<Input id="txtCompanyCode" value="362" width="20%"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element3" label="Plant">
<sap.ui.layout.form:fields>
<Input id="txtPlant" width="20%"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element4" label="Object Class">
<sap.ui.layout.form:fields>
<ComboBox id="cboxObjCls" width="20%">
<items>
<core:Item xmlns:core="sap.ui.core" id="item2" text="Investment" key="IV"/>
<core:Item xmlns:core="sap.ui.core" id="item3" text="Overhead" key="OC"/>
<core:Item xmlns:core="sap.ui.core" id="item4" text="Earnings, Sales" key="PA"/>
<core:Item xmlns:core="sap.ui.core" id="item5" text="Production" key="PR"/>
</items>
</ComboBox>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element6" label="Profit Center">
<sap.ui.layout.form:fields>
<Input id="input6" width="40%"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element7" label="Responsible CCtr">
<sap.ui.layout.form:fields>
<Input id="input7" width="40%"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element8" label="User Responsible">
<sap.ui.layout.form:fields><Input id="input8" width="40%"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element8_copy2" label="Request CCtr">
<sap.ui.layout.form:fields>
<Input id="input8_copy2" width="40%"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element8_copy4" label="WPS">
<sap.ui.layout.form:fields>
<Input id="input8_copy4" width="40%"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
<sap.ui.layout.form:FormElement id="element0">
<sap.ui.layout.form:fields >
<Button xmlns="sap.m" id="btnCreate" type="Accept" press="onCreate" text="Create"/>
<Button xmlns="sap.m" id="btnCancel" type="Reject" text="Cancel"/>
</sap.ui.layout.form:fields>
</sap.ui.layout.form:FormElement>
</sap.ui.layout.form:formElements>
</sap.ui.layout.form:FormContainer>
</sap.ui.layout.form:formContainers>
<sap.ui.layout.form:layout>
<sap.ui.layout.form:ResponsiveGridLayout id="layout0"/>
</sap.ui.layout.form:layout>
</sap.ui.layout.form:Form>
</content>
</IconTabFilter>
JS
var that = this;
var ioType = "";
var oEIDB = that.getView().byId("rbtnEIDB");
var oEUIB = that.getView().byId("rbtnEUIB");
if (oEIDB.getSelected()) {
ioType = "EUIB";
} else if (oEUIB.getSelected()) {
ioType = "EIBD";
}
var oIOdata = {};
oIOdata.Compcode = that.getView().byId("txtCompanyCode").getValue();
oIOdata.ControllingArea = that.getView().byId("txtContolArea").getValue();
oIOdata.Plant = that.getView().byId("txtPlant").getValue();
oIOdata.ObjectClass = that.getView().byId("cboxObjCls").getSelectedKey();
oIOdata.OrderName = that.getView().byId("txtDesc").getValue();
oIOdata.UserRespons = that.getView().byId("txtUserResp").getValue();
oIOdata.ProfitCenter = that.getView().byId("txtProfitCenter").getValue();
oIOdata.RespCostCenter = that.getView().byId("txtRespCCtr").getValue();
oIOdata.ReqCostCenter = that.getView().byId("txtReqCCtr").getValue();
oIOdata.OrderNumber = that.getView().byId("txtIONo").getValue();
oIOdata.OrderType = ioType;
OData.request({
requestUri: "/sap/opu/odata/AAG362/FI_INTERNAL_ORDER_SRV/InternalOrderSet",
method: "GET",
headers: {
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token": "Fetch"
}
},
function (data, response) {
header_xcsrf_token = response.headers['x-csrf-token'];
var oHeaders = {
"x-csrf-token": header_xcsrf_token,
'Accept': 'application/json',
};
OData.request({
requestUri: "/sap/opu/odata/AAG362/FI_INTERNAL_ORDER_SRV/InternalOrderSet",
method: "POST",
headers: oHeaders,
data: oIOdata
},
function (data, request) {
alert("Internal Order Created");
location.reload(true);
},
function (err) {
alert("Creation failed");
});
},
function (err) {
var request = err.request;
var response = err.response;
alert("Error in GET -- Request " + request + " Response " + response);
});
OData
<entry><id>http://elagwci1d.nat.tds.rz:8000/sap/opu/odata/AAG362/FI_INTERNAL_ORDER_SRV/InternalOrderSet('')</id><a xmlns="http://www.w3.org/1999/xhtml" style="color: blue; margin-left: -2em;"><<span style="color: rgb(153, 0, 0);">title</span> <span style="color: rgb(153, 0, 0);">type</span>="<span style="color: black; font-weight: bold;">text</span>"></a>InternalOrderSet('')<span xmlns="http://www.w3.org/1999/xhtml" style="color: blue;"></<span style="color: rgb(153, 0, 0);">title</span>></span><updated>2018-12-24T12:48:14Z</updated><category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="AAG362.FI_INTERNAL_ORDER_SRV.InternalOrder"/><link title="InternalOrder" rel="self" href="InternalOrderSet('')"/><content type="application/xml"><m:properties xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><d:Compcode/><d:ControllingArea/><d:Plant/><d:ObjectClass/><d:OrderName/><d:UserRespons/><d:ProfitCenter/><d:RespCostCenter/><d:ReqCostCenter/><d:OrderNumber/><d:WBS/><d:OrderType/></m:properties></content></entry>
How do I resolve this error???
I also read about using ODataModel.create()... would that be better...
please help and advice
Thanking You
Siddharth
Request clarification before answering.
Hi Siddharth,
You should always use the ui5 odata to perform the crud operations. check the reference api below:
https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel
Also, do not instantiate the odata service in your code manually. you can use the manifest.json which will automatically instantiate your service.
Ideally in manifest.json, you will make your odata model as nameless model.
In you app, get the model and call the create
this.getView().getModel().create("/EntitysetName",{properties:properties}, {
success: function(mData){
}.bind(this),
error: function(mData){
}.bind(this)
});https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel/methods/create
I also suggest you to use the webide to generate the initial template(worklist) this will auto generate the basic code for you, later you can delete the files that you dont want and build on top of it, it also has the automatic instantiation of the odata model inside the manifest.
BR,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hii Mahesh,
I tried the code above:
oModel.create("/InternalOrderSet", oIOdata, {
success: function (oData, response) {
console.log(response);
MessageBox.show(oData.OrderNumber + " has been Created");
}.bind(this),
error: function (oError) {
MessageBox.show(oError + ": Error has occurred");
}.bind(this)
});it worked, I get a 201 status but the IO does not get created at the backend. I ran the service in Frontend server there it worked. am I missing something here??
regards
Siddharth
Hi Siddharth,
1. "I ran the service in Frontend server there it worked." ? I didnt understand this part, ran in front end server means, you tried in gw_client tcode?
2. If the status is 201 means, it is success, now you need to put an external breakpoint in that redefined create method and check if the code is working or not.
BR,
Mahesh
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.