cancel
Showing results for 
Search instead for 
Did you mean: 

duplicate id error while viewing tile in launchpad for 2nd time

amber_garg
Active Participant

Whenever clicking on a tile for 2nd time in a fiori launchpad , I am getting the duplicate id error for few controls. I searched on SCN and accordingly tried with createId() but still the error perists (it shows duplicate id for <viewid>--<id> in console error) which means even the id's generated using createId having the view id prefixed to it are also not getting cleared when the application is exited in 1st attempt

Strangely though , I have declared  number of controls in my app using hardcoded id's but the duplicate id comes only for few controls like BusyDialog , OverlayDailog , Carousel and Label. The error does not come for sap.m.List which is also having a hardcoded id.

Regards

Amber

Accepted Solutions (1)

Accepted Solutions (1)

saxos
Explorer
0 Kudos

Hi Amber,

I had this problem also. But I can't remember how I fixed it .

Does your component.js have:

destroy: function() {
this._oErrorHandler.destroy(); //only if you have one
// call the base component's destroy function
UIComponent.prototype.destroy.apply(this, arguments);

},

Try this pls.

Regards

Samuel

amber_garg
Active Participant
0 Kudos

Hi Samuel,

Thanks for your reply. Do I need attach the above destroy function to some event and then define the destroy the method in controller or can I write in onExit hook method of controller.

As you said I need to write it in Component.js , should I be writing it inside metadata , dependencies

As per the link below , Component.js has only 2 methods , init and createContent()

The component.js looks like this currently

https://help.sap.com/saphelp_uiaddon10/helpdata/en/b4/30345887f1419fba50320b57c1bdf9/content.htm?fra...

saxos
Explorer
0 Kudos

Write it like createContent/onInit Function.

"destroy" should be called automatically as you leave your application.

for example:

onInit: function() {

     ...code code code

},

destory: function(){

}

amber_garg
Active Participant
0 Kudos

Hi Samuel,

While navigating back to home page (Exit on the app) , I get the error message in Console saying UIComponent is not defined

My code is as follows

Regards

Amber

saxos
Explorer
0 Kudos

than just write sap.ui.core.UIComponent.prototype.destroy.apply(this,arguments);

amber_garg
Active Participant
0 Kudos

Hi Samuel,


I tried but still the duplicate id is coming.


Regards

Amber

saxos
Explorer
0 Kudos

Before you create a new BusyDialog you should check if its already initialized.

You could make the BusyDialog global so you can access it from any function which you could need.

for example:

if(!this.oBusy_Dialog) {

     this.oBusy_Dialog = new sap.m.BusyDialog(...);

}

amber_garg
Active Participant
0 Kudos

Hi Samuel,

Thanks for your continuous help. Actually you are right in the sense that if I declare it globally and give the above if condition it would solve the issue but the thing is that this is error coming for few other controls also which are specific to a view and hence cannot be declared globally. In such a case if controls are not declared globally , the above If condition does not work as each time these controls are shown as undefined in console and hence enter inside the if condition every time thereby revoking the error. Ideally this is logical since the control objects been declared locally inside the view are expected to be dead as soon the the application is exited and hence they start afresh each time we click on tile thus entering inside IF . However still it gives the duplicate id error.

Is there anything wrong with respect to coding structure/standard which I am missing in my code. Also this IF condition workaround might not be able to work if we use XML views I guess.

Any help would be greatly appreciated

Regards

Amber

jamie_cawley
Advisor
Advisor
0 Kudos

Are you using this.createId in the views?  It would be helpful to see their definition.

Regards,

Jamie

SAP - Technology RIG

amber_garg
Active Participant
0 Kudos

Yes , below is the code I am using to declare

var oBusy_Dial = new sap.m.BusyDialog(this.createId("BusyDial"),

                                {

                                      text: "Fetching Data......",

                                      title: "Please Wait",

                                      customIcon: jQuery.sap.getModulePath("ArtViewer")+"/Images/load_icon1.png"

                                        });

Regards

Amber

saxos
Explorer
0 Kudos

Hi Amber,

could you please make a breakingpoint in the destroy function to check if he goes in? I just outcommented my destroy function in my component.js and i get this as i clicked on the tile for the second time. (clicked on the tile, clicked on the home button, clicked on the tile):

As i said further, I had this problem a little time ago too and I think I solved it with this function.

Regards

Samuel

amber_garg
Active Participant
0 Kudos

Hi Samuel,

Thanks for your reply. Yes I tried putting breakpoint inside the destroy function and its indeed getting triggered when i click on home button (to navigate back to launchpad home page)

However one thing I noticed was that the "arguments" which we are passing as parameters in destroy.apply functions , are shown as undefined in console inside the destroy function


destroy: function() {

  // this._oErrorHandler.destroy(); //only if you have one

  // call the base component's destroy function

  debugger;

  sap.ui.core.UIComponent.prototype.destroy.apply(this, arguments);

    },

Thanks

Amber

saxos
Explorer
0 Kudos

Hi Amber,

I just debugged my program. In my case it's not undefined. Could you please try writing this in your init-function:

sap.ui.core.UIComponent.prototype.init.apply(this, arguments);

amber_garg
Active Participant
0 Kudos

Hi Samuel,

I wrote the above line in init function. Now what is happening is inside init function for 1st time , the arguments is defined but empty [] . When i click the tile for 1st time , it loads my app normally. Then I click on Home and the destroy method gets called and breakpoint inside debugger also gets triggered. This time arguments is defined but empty [] . The launchpad homepage is displayed. Then I click on tile for 2nd time , this time again the init method gets called and breakpoint inside it gets triggered. However this time , the argument is undefined (seems it got destroyed or something during the last destroy call)

Hence 2nd time on loading the tile , in addition to the previous duplicate errors , I am getting the error for arguments not defined as well.

Regards

Amber

saxos
Explorer
0 Kudos

Well this ID is the ID of your busydialog which we talked about before.

After you close your oBusy_Dialog try:

oBusy_Dialog.destroy();

you should get the same error if you open your busydialog for the second time by the way. Shouldn't be an App-Reopen problem this time.

amber_garg
Active Participant
0 Kudos

Hi Samuel,

Yes you were right. What i did now was I removed the init and destroy method redefinition in my Component.js. Instead of that I used exit method in the Controller of the particular view , and inside that i destroyed all my UI controls one by one individually (Busy Dialog , Image etc all which were causing the duplicate id error) ,

Now I am not facing any issues and the app is working fine the 2nd time also from the launchpad.

Just I had one doubt , instead of destroying all the components individually (there might be 30-40 of them in a view in real time app) , is there any other way. Wanted to know if the practice we followed is fine from the standards or we can still improve it.

I tried to destroy the View itself rather than the UI controls inside it hoping that destroying the view might automatically destroy the components inside it , but I get the error "core-min-1.js:16 Uncaught RangeError: Maximum call stack size exceeded" error when clicking on Home button to navigate back to home page from the app. Hence not sure if its possible to do this in a better way or not

Thanks a lot Samuel for your patience and continuous suggestions

Regards

Amber

agentry_src
Active Contributor
0 Kudos

Hi Amber,

New question, new Discussion please.  This thread is now locked.  Your new Discussion should probably link back to this one for historical perspective. 

NOTE: Getting the link is easy enough for both the author and Blog.  Simply MouseOver the item, Right Click, and select Copy Shortcut.  Paste it into your Discussion.  You can also click on the url after pasting.  Click on the A to expand the options and select T (on the right) to Auto-Title the url.

Thanks, Mike (Moderator)

SAP Technology RIG

Answers (1)

Answers (1)

SergioG_TX
Active Contributor
0 Kudos

the reason for duplicate ids is if you have 2 views and you use the same id, that may cause duplicate ids. you can solve it by making it unique through your application (recommended) or... by using a dynamic id (don't assign one - do not recommend as you may need to reference your objects via ID)

amber_garg
Active Participant
0 Kudos

Hi Sergio,

I have defined the unique ID's only throughout the application that's why its working the first time (Otherwise it should hv given this error , the first time itself while navigating between the views) . The problem comes when I exit the application (By clicking on Home Page button of Launchpad) and then click on the same tile again. While doing this again my app is loaded and again all the id's are getting created with the same name (and some of them seems to be not destroyed/deleted during previous exit)

As you said , I have to assign the id as I need to reference them in my code at various points.

Regards

Amber

saxos
Explorer
0 Kudos

The views arent getting destroyed but the program wanna open it again as you click on your tile. That's why it will be duplicated. As i mentioned try the destroy function. Should get called automatically.

Regards

Samuel