Skip to Content
avatar image
Former Member

Dialog Screen is working on first time but not at all time.

Hello expert,

While I'm developing my project I add a button which is calling a dialog screen but on first time its working perfect. But If I want to press the button one more time there is a error like this: "Uncaught Error: The object with ID pddepLayout1 was destroyed and cannot be used anymore."

Please help this situation.

Here is my all code :

var opddepButton1 = new sap.m.Button('opddepButton1',{text:'Ekle',

  press:function(oEvent){



  oDialog.setBindingContext(oEvent.oSource
            .getBindingContext());
  openDialog();

    }
    
    });
                 
                
  function openDialog() {
       oDialog.destroyContent();
   
    var opddepButton = new sap.m.Button('opddepButton',{text:'Ekle',press:function(){
     
     
            var fname = sap.ui.getCore().byId('pdmalkod').getValue();
            var lname = sap.ui.getCore().byId('pdparti').getValue();
            var aname = sap.ui.getCore().byId('pdmiktar').getValue();
            var bname = sap.ui.getCore().byId('pdolcbir').getValue();
            var cname = sap.ui.getCore().byId('pdmasyer').getValue();
            var dname = sap.ui.getCore().byId('pdnedekod').getValue();
            
            mdData.clients.push({"id":fname,"parti":lname,"miktar":aname,"olcbirimi":bname,"masyeri":cname,"nedkodu":dname });
            oModel.setData(mdData);
            
            oDialog.close();
            
            
            
            
            }
            
            });


    var labelidmalkod = new sap.m.Label('labelidmalkod',{text:'Malzeme Kodu:'
            
        });
        var pdmalkod = new sap.m.Input('pdmalkod',{
        
        });
       var labelidparti = new sap.m.Label('labelidparti',{text:'Parti:'
        
        });
       var pdparti = new sap.m.Input('pdparti',{
        
        });
       
       var labelidmiktar = new sap.m.Label('labelidmiktar',{text:'Miktar:'
           
       });
      var pdmiktar = new sap.m.Input('pdmiktar',{
       
       });
      
      var labelidolcbir = new sap.m.Label('labelidolcbir',{text:'Ölçü Birimi:'
        
      });
     var pdolcbir = new sap.m.Input('pdolcbir',{
      
      });
     
     var labelidmasyer = new sap.m.Label('labelidmasyer',{text:'Masraf Yeri:'
        
     });
    var pdmasyer = new sap.m.Input('pdmasyer',{
     
     });
     
    var labelidnedkod = new sap.m.Label('labelidnedkod',{text:'Neden Kodu:'
        
    });
    var pdnedekod = new sap.m.Input('pdnedekod',{
     
    });
       
     pddepLayout1.createRow(labelidmalkod, pdmalkod);
       
     pddepLayout1.createRow(labelidparti, pdparti);
     
     pddepLayout1.createRow(labelidmiktar, pdmiktar);
     
     pddepLayout1.createRow(labelidolcbir, pdolcbir);
     
     pddepLayout1.createRow(labelidmasyer, pdmasyer);
     
     pddepLayout1.createRow(labelidnedkod, pdnedekod);
     pddepLayout1.createRow(opddepButton);
     
     oDialog.addContent(pddepLayout1);
     
     
     
     oDialog.open();
   
    };

Thanks,

Ogulcan G.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Oct 16, 2015 at 01:44 PM

    Hi Ogulcan,


    I guess pddepLayout1 is a Matrix Layout. You are adding this layout to a dialog content.


    Instead of destroying content, why don't you use .removeAllRows() method of Matrix Layout. Something like this -

     function openDialog() {  
           var oLayout = sap.ui.getCore().byId("pddepLayout1");          //Get Hold of Matrix Layout
        oLayout.removeAllRows();               //Remove all Rows of Matrix Layout
        //and then your code
    }
    

    Regards,

    Sai Vellanki.


    Add comment
    10|10000 characters needed characters exceeded

  • Oct 16, 2015 at 07:20 AM

    Hi Ogulcan,

    I think it´s because you "destroy the content" (line 12 in your code snippet) of the dialog when open it. At first time pddepLayout1 is not part of the content. So it works. After first call pddepLayout1 is part of the content as you added it in line 89. So it will be destroyed and afterwards you can´t use it anymore. So I don´t know what´s the best approach in your case but maybe you should consider only destroying the content of pddepLayout1 and not the content of the complete dialog.

    Best regards,

    Sebastian

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Sebastian,

      Yeah I agree with you but I still couldn't fix my problem even try change where defination of pddepLayout1 and also change type of layout (for ex. border). I'm trying also right now another solutions but doesnt work for me.

      Thank you for answering,

      Ogulcan G.