Skip to Content
0

Once choose select dropdown field then dynamically it will appear another child dropdown field

May 12, 2017 at 02:34 PM

79

avatar image
Former Member
I tried this code - to get the value from Odata for dropdown selection field.
When you click first select item field then one or more selection dropdown field (eg: select item ) will appear dynamically.
Below code i tried for dynamic generate field.


onPlantchange :function(){
var plant =sap.ui.getCore().byId("plant").getSelectedKey();if(plant!=0){

 var sServiceUrl ="/sap/opu/odata/SAP/Z_M_EPM_BOM_SRV/";

  var oModel =newsap.ui.model.odata.ODataModel(sServiceUrl, true);
  var filterList =[];

  var i;

 filterList.push(newsap.ui.model.Filter("Plant",sap.ui.model.FilterOperator.EQ,plant));

 oModel.read("/MatCharFieldSet",{context:null,

 async : false,filters: filterList,

 urlParameters:{"$expand" : "MatCharValuesSet"},

 success :function(data){
var res =data.results;for(i=0;i<res.length;i++){
 var fields=newsap.ui.layout.form.SimpleForm({
 editable : true,layout:"ResponsiveGridLayout",
 labelSpanL :5,
labelSpanM :5,
 adjustLabelSpan : false,
emptySpanL :0,
emptySpanM :0,
columnsL   :4,
 columnsM   :4,
 content :[newsap.m.Label({text:res[0].DescrChar,name:res[0].FieldName}),newsap.m.Select({
 items :[newsap.ui.core.Item ({text:res[i]. MatCharValuesSet.results[i].FieldValue ,key: res[i].MatCharValuesSet.results[i].FieldValue })
]
})
]
});
}
fields.placeAt("fields");
sap.ui.getCore().byId("fields").setVisible(true);
sap.ui.getCore().byId("plantSearch").setVisible(false);
}});

---------------------->

/MatCharFieldSet Json sample file:
Dyanamic Select Item list structure:

When i selected first select item like plant(Eg Choose Plant ) then it will show dynamic select item field like well field, well type, well location.

To Show Label: DescrChar (This Value : results/[0]/Descrchar)
To show Select Item: FieldValue (This Value :  results/[0]/MatCharValuesSet /results/[0]/ FieldValue. (eg: AOWQ))


SAMPLE JSON CODE:
object
d >
results>
[0]> __metadata >
      FieldName :MPP_WELL_FIELD
       Plant :Z009
       DescrChar :Well Field
       MatCharValuesSet
                >results
              [0]> _metadata
                   FieldValue : AOWQ
              [1]> _metadata
                   FieldValue : BQIA
              [2]> _metadata
                   FieldValue : RSDA
[1]> __metadata >
      FieldName :MPP_WELL_TYPE
       Plant :Z010
       DescrChar :Well Type
       MatCharValuesSet
                >results
              [0]> _metadata
                   FieldValue : JADA
              [1]> _metadata
                   FieldValue : YERE
              [2]> _metadata
                   FieldValue : SLJD
[2]> __metadata >
       FieldName :MPP_WELL_LOCATION
       Plant :Z011
       DescrChar :Well location
       MatCharValuesSet
                >results
              [0]> _metadata
                   FieldValue : UWEE
              [1]> _metadata
                   FieldValue : JKAS
              [2]> _metadata
                   FieldValue : QEET


img-41531.jpg (91.9 kB)
10 |10000 characters needed characters left characters exceeded

type your question clearly...and show screenshots of the issue

0
Former Member
Srikanth KV

I tried this code - to get the value from Odata for dropdown selection field.

When you click first select item field then one or more selection dropdown field (eg: select item ) will appear dynamically.

Below code i tried for dynamic generate field.

onPlantchange :function(){
var plant =sap.ui.getCore().byId("plant").getSelectedKey();if(plant!=0){

 var sServiceUrl ="/sap/opu/odata/SAP/Z_M_EPM_BOM_SRV/";

  var oModel =newsap.ui.model.odata.ODataModel(sServiceUrl, true);
  var filterList =[];

  var i;

 filterList.push(newsap.ui.model.Filter("Plant",sap.ui.model.FilterOperator.EQ,plant));

 oModel.read("/MatCharFieldSet",{context:null,

 async : false,filters: filterList,

 urlParameters:{"$expand" : "MatCharValuesSet"},

 success :function(data){
var res =data.results;for(i=0;i<res.length;i++){
 var fields=newsap.ui.layout.form.SimpleForm({
 editable : true,layout:"ResponsiveGridLayout",
 labelSpanL :5,
labelSpanM :5,
 adjustLabelSpan : false,
emptySpanL :0,
emptySpanM :0,
columnsL   :4,
 columnsM   :4,
 content :[newsap.m.Label({text:res[0].DescrChar,name:res[0].FieldName}),newsap.m.Select({
 items :[newsap.ui.core.Item ({text:res[i]. MatCharValuesSet.results[i].FieldValue ,key: res[i].MatCharValuesSet.results[i].FieldValue })]})]});}fields.placeAt("fields");sap.ui.getCore().byId("fields").setVisible(true);sap.ui.getCore().byId("plantSearch").setVisible(false);}});

MatCharFieldSet Json sample file:

Dyanamic Select Item list structure:

When i selected first select item like plant(Eg Choose Plant ) then it will show dynamic select item field like well field, well type, well location.

To Show Label: DescrChar (This Value : results/[0]/Descrchar)
To show Select Item: FieldValue (This Value :  results/[0]/MatCharValuesSet /results/[0]/ FieldValue. (eg: AOWQ))


SAMPLE JSON CODE:
object
d >
results>
[0]> __metadata >
      FieldName :MPP_WELL_FIELD
       Plant :Z009
       DescrChar :Well Field
       MatCharValuesSet
                >results
              [0]> _metadata
                   FieldValue : AOWQ
              [1]> _metadata
                   FieldValue : BQIA
              [2]> _metadata
                   FieldValue : RSDA
[1]> __metadata >
      FieldName :MPP_WELL_TYPE
       Plant :Z010
       DescrChar :Well Type
       MatCharValuesSet
                >results
              [0]> _metadata
                   FieldValue : JADA
              [1]> _metadata
                   FieldValue : YERE
              [2]> _metadata
                   FieldValue : SLJD
[2]> __metadata >
       FieldName :MPP_WELL_LOCATION
       Plant :Z011
       DescrChar :Well location
       MatCharValuesSet
                >results
              [0]> _metadata
                   FieldValue : UWEE
              [1]> _metadata
                   FieldValue : JKAS
              [2]> _metadata
                   FieldValue : QEET

0
Former Member
Srikanth KV

for project concept- pls check attached file

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
avatar image
Former Member May 20, 2017 at 12:08 PM
0

onPlantchange : function(){

var plant = sap.ui.getCore().byId("plant").getSelectedKey();

if(plant!=0){


var sServiceUrl = "/sap/opu/odata/SAP/Z_M_EPM_BOM_SRV/";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
var filterList =[];
var i;

filterList.push(new sap.ui.model.Filter("Plant",sap.ui.model.FilterOperator.EQ,plant));
oModel.read("/MatCharFieldSet",{
context : null,
async : false,
filters : filterList,
urlParameters:{"$expand" : "MatCharValuesSet"},
success : function(data){
var res = data.results;
var content=[];
for ( i = 0; i < res.length; i++) {

content.push(new sap.m.Label({text:res[i].DescrChar,name :res[i].FieldName}));
var items=[];
for (var j = 0; j < res[i].MatCharValuesSet.results.length; j++)
{
items.push(new sap.ui.core.Item ({text:res[i].MatCharValuesSet.results[j].FieldValue,key : res[i].MatCharValuesSet.results[j].FieldValue}));

}
content.push(new sap.m.Select({items :items}));
}
fields = new sap.ui.layout.form.SimpleForm({

editable : true,
layout : sap.ui.layout.form.SimpleFormLayout.ResponsiveGridLayout,
labelSpanL : 4,
labelSpanM : 4,
adjustLabelSpan : true,
emptySpanL : 0,
emptySpanM : 0,
columnsL : 4,
columnsM : 4,
content : content

});

fields.placeAt("fields","only");
sap.ui.getCore().byId("fields").setVisible(true);

sap.ui.getCore().byId("plantSearch").setVisible(false);
sap.ui.getCore().byId("Get").setVisible(true);

}

Share
10 |10000 characters needed characters left characters exceeded