on 03-20-2015 1:09 PM
Hi all,
Iam trying to update object with header and items to perform deep entity insert.But the create_entity method is only triggered and not the Create_deep_entity.
Head entity definition in MPC
*Head entity----------------------------------------------------------------
*-----------------------------------------------------------------------------------------
lcr_delhead_entity = model->create_entity_type( 'delhead' )."delivery items
"create needed properties of entity "Spool"
build_props_by_structname( iv_structname = 'GOODS_RCPT_SI_S'
icr_entity = lcr_delhead_entity ).
"enhance property behaviour
lo_property = lcr_delhead_entity->get_property( iv_property_name = 'DEL_NUM' ).
lo_property->set_is_key( ).
lo_property->set_type_edm_string( ).
lo_property = lcr_delivery_entity->get_property( iv_property_name = 'PRD_NUM' ).
lo_property->set_is_key( ).
lo_property->set_type_edm_string( ).
lcr_delhead_entity->bind_structure( 'GOODS_RCPT_SI_S' ).
"create entity sets of entity
lcr_entity_set_del_head = lcr_delhead_entity->create_entity_set( 'deliveryhead' ).
"set annotations for entity set behaviour
lcr_entity_set_del_head->set_creatable( abap_true ).
lcr_entity_set_del_head->set_updatable( abap_true ).
lcr_entity_set_del_head->set_deletable( abap_true ).
lcr_entity_set_del_head->set_addressable( abap_true ).
Item entity definition in MPC
* items entity----------------------------------------------------------------
*-----------------------------------------------------------------------------------------
lcr_delivery_entity = model->create_entity_type( 'delitems' )."delivery items
"create needed properties of entity "Spool"
build_props_by_structname( iv_structname = 'GOODS_RCPT_SI_S'
icr_entity = lcr_delivery_entity ).
"enhance property behaviour
lo_property = lcr_delivery_entity->get_property( iv_property_name = 'DEL_NUM' ).
lo_property->set_is_key( ).
lo_property->set_type_edm_string( ).
lo_property = lcr_delivery_entity->get_property( iv_property_name = 'PRD_NUM' ).
lo_property->set_is_key( ).
lo_property->set_type_edm_string( ).
lo_property = lcr_delivery_entity->get_property( iv_property_name = 'DEL_ITEM_NUM' ).
lo_property->set_is_key( ).
lo_property->set_type_edm_string( ).
lcr_delivery_entity->bind_structure( 'GOODS_RCPT_SI_S' ).
"create entity sets of entity
lcr_entity_set_del = lcr_delivery_entity->create_entity_set( 'deliverylist' ).
"set annotations for entity set behaviour
lcr_entity_set_del->set_creatable( abap_true ).
lcr_entity_set_del->set_updatable( abap_true ).
lcr_entity_set_del->set_deletable( abap_true ).
lcr_entity_set_del->set_addressable( abap_true ).
Navigation and associations
***********************************************************************************************************************************
* ASSOCIATIONS
***********************************************************************************************************************************
lo_association = model->create_association(
iv_association_name = 'delheadsettodelitemset' "#EC NOTEXT
iv_left_type = 'delhead' "#EC NOTEXT
iv_right_type = 'delitems' "#EC NOTEXT
iv_right_card = cardinality_feed"'N' "#EC NOTEXT
iv_left_card = cardinality_entity )."#EC NOTEXT
"iv_def_assoc_set = abap_false ). "#EC NOTEXT
"item to head
lo_association = model->create_association(
iv_association_name = 'delitemsettodeleadset' "#EC NOTEXT
iv_left_type = 'delitems' "#EC NOTEXT
iv_right_type = 'delhead' "#EC NOTEXT
iv_right_card = cardinality_entity"'N' "#EC NOTEXT
iv_left_card = cardinality_entity )."#EC NOTEXT
"iv_def_assoc_set = abap_false ). "#EC NOTEXT
***********************************************************************************************************************************
* NAVIGATION PROPERTIES
***********************************************************************************************************************************
* Navigation Properties for entity - delhead
"lo_entity_type = model->get_entity_type( iv_entity_name = 'delhead' ). "#EC NOTEXT
lcr_delhead_entity->create_navigation_property( iv_property_name = 'delheadtodellist' "#EC NOTEXT
iv_association_name = 'delheadsettodelitemset' ).
"lo_entity_type = model->get_entity_type( iv_entity_name = 'delitems' ). "#EC NOTEXT
lcr_delivery_entity->create_navigation_property( iv_property_name = 'dellisttodelhdead' "#EC NOTEXT
iv_association_name = 'delitemsettodeleadset' ).
UI code to update the deep entity
var requestORderHeader = {}; | |
requestORderHeader.PRD_NUM = "01"; | |
requestORderHeader.DEL_NUM = "01"; | |
requestORderHeader.DEL_ITEM_NUM = "01"; | |
requestORderHeader.ARTI_NUM = "P010"; | |
requestORderHeader.DEL_DESC = "200"; | |
requestORderHeader.SUB_DIV = null; | |
requestORderHeader.COLL_TYPE = null; | |
requestORderHeader.SEASON = null; | |
requestORderHeader.MAIN_CLASS = null; | |
requestORderHeader.CLASS = null; | |
requestORderHeader.GEN_ARTI_NUM = null; | |
requestORderHeader.DEL_QUAN = null; | |
requestORderHeader.QUANTITY = null; | |
var itemData = []; | |
itemData.push({ PRD_NUM: "01", DEL_NUM: "01" , DEL_ITEM_NUM: "01", ARTI_NUM: "P010", DEL_DESC: "200", SUB_DIV: null, COLL_TYPE: null, SEASON: null, MAIN_CLASS: null, CLASS: null, GEN_ARTI_NUM: null, DEL_QUAN: null , QUANTITY: null }); | |
//my navigation name delheadtodellist | |
requestORderHeader.delheadtodellist = itemData; |
// Retrieve model from controller | ||||
var oModel = sap.ui.getCore().getModel(); | ||||
oModel.create('/deliverylist', | ||||
requestORderHeader, | ||||
null, | ||||
function(oData, oResponse) { | ||||
debugger; | ||||
alert ('Order creation succeed !'); | ||||
}, | ||||
function(error) { | ||||
debugger; | ||||
alert('Call service creation failed'); | ||||
} | ||||
); |
but still only create_entity method is called and not the CREATE_DEEP_ENTITY method
what might be wrong in my code help me out
Thanks
Deepan
/IWBEP/IF_MGW_CORE_SRV_RUNTIME~CREATE_ENTITY and
/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY both method was redefined in the DPC class hence preference goes to CREATE_ENTITY and the same method is triggered.Now when i deleted the redefinition of CREATE_ENTITY method CREATE_DEEP_ENTITY is triggered now.
Thanks all!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
I have tried the batch process too.just incase it works but still only create_entity is only called not the create_deep_entity.
var oModel = sap.ui.getCore().getModel();
//batch
var batchChanges = [];
batchChanges.push(oModel.createBatchOperation("/deliveryhead","POST",requestORderHeader));
oModel.addBatchChangeOperations(batchChanges);
oModel.submitBatch(function(data){
debugger;
},function(err){
debugger;
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Can you please try this,
var obj = { "PRD_NUM": "01", "DEL_NUM": "01" , "DEL_ITEM_NUM": "01", "ARTI_NUM": "P010", "DEL_DESC": "200", "SUB_DIV": null, "COLL_TYPE": null, "SEASON": null, "MAIN_CLASS": null, "CLASS": null, "GEN_ARTI_NUM": null, "DEL_QUAN": null , "QUANTITY": null };
var requestORderHeader = {"delheadtodellist" : obj};
var oModel = sap.ui.getCore().getModel(); | ||||
oModel.create('/deliverylist', | ||||
requestORderHeader, | ||||
null, | ||||
function(oData, oResponse) { | ||||
debugger; | ||||
alert ('Order creation succeed !'); | ||||
}, | ||||
function(error) { | ||||
debugger; | ||||
alert('Call service creation failed'); | ||||
} | ||||
); |
Thanks vinay.
yes i have an read operation
sdelread = "/deliverylist"
this.getView().byId("idProductsTable").bindItems(sdelRead,oTemplate,false,filters);
Hi Vinay,
u mean the navigation part ? yes it is there
{
"d" : {
"results" : [
{
"__metadata" : {
"id" : "http://testserver.en:8005/sap/opu/odata/Sap/testGOODS_RCPT_SRV/deliverylist(PRD_NUM='',DEL_NUM='0182397083',DEL_ITEM_NUM='000010')",
"uri" : "http://testserver.en:8005/sap/opu/odata/Sap/testGOODS_RCPT_SRV/deliverylist(PRD_NUM='',DEL_NUM='0182397083',DEL_ITEM_NUM='000010')",
"type" : "RT_SRS_GOODS_RCPT_SRV.delitems"
},
"PRD_NUM" : "",
"DEL_NUM" : "0182397083",
"DEL_ITEM_NUM" : "000010",
"ARTI_NUM" : "000000001101732001",
"DEL_DESC" : "11.305.12.4288 Blouse, 44D6, 34",
"SUB_DIV" : "",
"COLL_TYPE" : "",
"SEASON" : "05",
"MAIN_CLASS" : "",
"CLASS" : "",
"GEN_ARTI_NUM" : "",
"DEL_QUAN" : "1.000",
"QUANTITY" : "1.000",
"dellisttodelhdead" : {
"__deferred" : {
"uri" : "http://testserver.en:8005/sap/opu/odata/Sap/testGOODS_RCPT_SRV/deliverylist(PRD_NUM='',DEL_NUM='0182..."
}
}
},
var sPath = "/deliverylist(PRD_NUM='',DEL_NUM='0182397083',DEL_ITEM_NUM='000010')/dellisttodelhdead"
var obj = { "PRD_NUM": "01", "DEL_NUM": "01" , "DEL_ITEM_NUM": "01", "ARTI_NUM": "P010","DEL_DESC": "200", "SUB_DIV": null, "COLL_TYPE": null, "SEASON": null, "MAIN_CLASS": null, "CLASS": null, "GEN_ARTI_NUM": null, "DEL_QUAN": null , "QUANTITY": null };
var requestORderHeader = {"delheadtodellist" : obj};
var oModel = sap.ui.getCore().getModel(); | ||||
oModel.create(sPath, | ||||
requestORderHeader, | ||||
null, | ||||
function(oData, oResponse) { | ||||
debugger; | ||||
alert ('Order creation succeed !'); | ||||
}, | ||||
function(error) { | ||||
debugger; | ||||
alert('Call service creation failed'); | ||||
} | ||||
); |
Hi all,
What might be the issue ? as you can see above ..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Deepan,
Why don't you try with $ajax first.
I have got oModel.Create() working before, but not sure why is it not working for you.
Documentation says that it is not officially supported. JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel
Hello Deepan,
Please check the payload which you are sending has the navigation property which is defined between Header and Item Entities in your GW Model.
Below would help :
Sample Payload in Json Format ->
Where HeaderItem would be the navigation property defined in your GW Model.
{
"Id":"01",
"Name":"John",
"Name2":"Simon",
"HeaderItem":
[
{"Id":"10","Name1":"Test1"},
{"Id":"20","Name2":"Test2"}
]
}
Cross Check your payload again.
Regards,
Ashwin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes i have given the navigation property name.
- <EntityType sap:content-version="1" Name="delhead">-
- <Key><PropertyRef Name="DEL_NUM"/></Key><
- <property Name="PRD_NUM" sap:label="Purchasing Doc." MaxLength="10" Type="Edm.String"/>
- <Property Name="DEL_NUM" sap:label="Delivery" MaxLength="10" Nullable="false" Type="Edm.String"/>
- <Property Name="DEL_ITEM_NUM" sap:label="Item" MaxLength="6" Type="Edm.String"/>
- <Property Name="ARTI_NUM" sap:label="Article" MaxLength="18" Type="Edm.String"/>
- <Property Name="DEL_DESC" sap:label="Description" MaxLength="40" Type="Edm.String"/><
- <Property Name="SUB_DIV" sap:label="Sub Division" MaxLength="3" Type="Edm.String"/>
- <Property Name="COLL_TYPE" sap:label="Collection Type" MaxLength="2" Type="Edm.String"/>
- <Property Name="SEASON" sap:label="Season" MaxLength="4" Type="Edm.String"/>
- <Property Name="MAIN_CLASS" sap:label="Main Class" MaxLength="2" Type="Edm.String"/><
- <Property Name="CLASS" sap:label="Class" MaxLength="3" Type="Edm.String"/>
- <Property Name="GEN_ARTI_NUM" sap:label="Cross-site CM" MaxLength="18" Type="Edm.String"/><
- <Property Name="DEL_QUAN" sap:label="Target quantity" Type="Edm.Decimal" Scale="3" Precision="13"/><
- <Property Name="QUANTITY" sap:label="Target quantity" Type="Edm.Decimal" Scale="3" Precision="13"/><
- <NavigationProperty Name="delheadtodellist" ToRole="ToRole_delheadsettodelitemset" FromRole="FromRole_delheadsettodelitemset" Relationship="GOODSRCPT.delheadsettodelitemset"/>
- </EntityType>
I have used property name as delheadtodelist
I am passing the same name still create_deep_entity method is not triggered
var requestORderHeader = {};
requestORderHeader.PRD_NUM = "01";
requestORderHeader.DEL_NUM = "01";
requestORderHeader.DEL_ITEM_NUM = "01";
requestORderHeader.ARTI_NUM = "P010";
requestORderHeader.DEL_DESC = "200";
requestORderHeader.SUB_DIV = null;
requestORderHeader.COLL_TYPE = null;
requestORderHeader.SEASON = null;
requestORderHeader.MAIN_CLASS = null;
requestORderHeader.CLASS = null;
requestORderHeader.GEN_ARTI_NUM = null;
requestORderHeader.DEL_QUAN = null;
requestORderHeader.QUANTITY = null;
var itemData = [];
itemData.push({ PRD_NUM: "01", DEL_NUM: "01" , DEL_ITEM_NUM: "01", ARTI_NUM: "P010", DEL_DESC: "200", SUB_DIV: null, COLL_TYPE: null, SEASON: null, MAIN_CLASS: null, CLASS: null, GEN_ARTI_NUM: null, DEL_QUAN: null , QUANTITY: null });
requestORderHeader.delheadtodellist = itemData;
oModel.create('/deliveryhead',
requestORderHeader,
null,
function(oData, oResponse) {
debugger;
alert ('Order creation succeed !');
},
function(error) {
debugger;
alert('Call service creation failed');
}
);
Deepan,
Framework decides to call Deep Entity method or the regular create method based on the request content. If the request content has children, then deep entity is called.
Call $metadata of your service and check if right navigation property is available.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Krishna ,
Navigation seems to be correct.please find the below metadata.but still its not working. ,Always create_entity method get called.
Head Entity
<EntityType sap:content-version="1" Name="delhead">-
<Key><PropertyRef Name="DEL_NUM"/></Key><
<property Name="PRD_NUM" sap:label="Purchasing Doc." MaxLength="10" Type="Edm.String"/>
<Property Name="DEL_NUM" sap:label="Delivery" MaxLength="10" Nullable="false" Type="Edm.String"/>
<Property Name="DEL_ITEM_NUM" sap:label="Item" MaxLength="6" Type="Edm.String"/>
<Property Name="ARTI_NUM" sap:label="Article" MaxLength="18" Type="Edm.String"/>
<Property Name="DEL_DESC" sap:label="Description" MaxLength="40" Type="Edm.String"/><
<Property Name="SUB_DIV" sap:label="Sub Division" MaxLength="3" Type="Edm.String"/>
<Property Name="COLL_TYPE" sap:label="Collection Type" MaxLength="2" Type="Edm.String"/>
<Property Name="SEASON" sap:label="Season" MaxLength="4" Type="Edm.String"/>
<Property Name="MAIN_CLASS" sap:label="Main Class" MaxLength="2" Type="Edm.String"/><
<Property Name="CLASS" sap:label="Class" MaxLength="3" Type="Edm.String"/>
<Property Name="GEN_ARTI_NUM" sap:label="Cross-site CM" MaxLength="18" Type="Edm.String"/><
<Property Name="DEL_QUAN" sap:label="Target quantity" Type="Edm.Decimal" Scale="3" Precision="13"/><
<Property Name="QUANTITY" sap:label="Target quantity" Type="Edm.Decimal" Scale="3" Precision="13"/><
<NavigationProperty Name="delheadtodellist" ToRole="ToRole_delheadsettodelitemset" FromRole="FromRole_delheadsettodelitemset" Relationship="GOODSRCPT.delheadsettodelitemset"/>
</EntityType>
Item Entity
<EntityType sap:content-version="1" Name="delitems">-<Key><PropertyRef Name="PRD_NUM"/><PropertyRef Name="DEL_NUM"/>
<PropertyRef Name="DEL_ITEM_NUM"/></Key>
<Property Name="PRD_NUM" sap:label="Purchasing Doc." MaxLength="10" Nullable="false" Type="Edm.String"/>
<Property Name="DEL_NUM" sap:label="Delivery" MaxLength="10" Nullable="false" Type="Edm.String"/>
<Property Name="DEL_ITEM_NUM" sap:label="Item" MaxLength="6" Nullable="false" Type="Edm.String"/>
<Property Name="ARTI_NUM" sap:label="Article" MaxLength="18" Type="Edm.String"/>
<Property Name="DEL_DESC" sap:label="Description" MaxLength="40" Type="Edm.String"/>
<Property Name="SUB_DIV" sap:label="Sub Division" MaxLength="3" Type="Edm.String"/>
<Property Name="COLL_TYPE" sap:label="Collection Type" MaxLength="2" Type="Edm.String"/>
<Property Name="SEASON" sap:label="Season" MaxLength="4" Type="Edm.String"/>
<Property Name="MAIN_CLASS" sap:label="Main Class" MaxLength="2" Type="Edm.String"/>
<Property Name="CLASS" sap:label="Class" MaxLength="3" Type="Edm.String"/>
<Property Name="GEN_ARTI_NUM" sap:label="Cross-site CM" MaxLength="18" Type="Edm.String"/>
<Property Name="DEL_QUAN" sap:label="Target quantity" Type="Edm.Decimal" Scale="3" Precision="13"/><Property Name="QUANTITY" sap:label="Target quantity" Type="Edm.Decimal" Scale="3" Precision="13"/>
<NavigationProperty Name="dellisttodelhdead" ToRole="ToRole_delitemsettodeleadset" FromRole="FromRole_delitemsettodeleadset" Relationship="GOODSRCPT.delitemsettodeleadset"/>
</EntityType>
Associations
<Association sap:content-version="1" Name="delheadsettodelitemset">
<End Type="GOODSRCPT.delhead" Role="FromRole_delheadsettodelitemset" Multiplicity="1"/>
<End Type="GOODSRCPT.delitems" Role="ToRole_delheadsettodelitemset" Multiplicity="*"/>
</Association>-
<Association sap:content-version="1" Name="delitemsettodeleadset">
<End Type="GOODSRCPT.delitems" Role="FromRole_delitemsettodeleadset" Multiplicity="*"/>
<End Type="GOODSRCPT.delhead" Role="ToRole_delitemsettodeleadset" Multiplicity="1"/></Association>
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.