Service Portal destroy spUtil widget

drberg
Giga Contributor

How can I destroy a widget created with spUtil?

I thought i could destroy a widget with toggling an ng-if boolean like this:

<div ng-if="c.showWidget">

  <sp-widget widget="c.myWidget"></sp-widget>

</div>

I thought that if c.showWidget is false, then the c.myWidget data would disappear from memory.

But it doesn't.

Rather, when I show the widget again it will load with the old data. Investigating further I see that on run #1 it runs the server script first, but on run #2 and more it starts with client script, then runs the server script. This causes me to work with the old data because the data isn't fresh from the server until after it has been presented.

This is how I call the widget:

c.showAbsChk = true;

spUtil.get('rcn-boden-modal-abs-chk', { "obj": { "type": "MY_TYPE", "sysId": aSysId } }).then(function(response) {

  c.myWidget = response;

});

Any ideas on how I can fix this?

1 ACCEPTED SOLUTION

drberg
Giga Contributor

I found this here:


Note: As of all versions of Helsinki, any options passed into this function will only be available in the embedded widget's server script on the first execution of that script. Any subsequent calls into the server script from the embedded widget will not contain the object properties passed in. This is something we are investigating for a future version of Helisinki or Istanbul.


It seems to be the answer on why it's behaving the way it is.



I have found an ugly work around for this that seems to work for me:


The widget has three layers: widget 1 starts widget 2, widget 2 starts widget 3.


The workaround was emitting a message to w1 to toggle w2 off and on again. This seems to recreate w3 correctly.



It's ugly, but it seems to work for the moment.



Does anyone know of a more elegant workaround?


View solution in original post

5 REPLIES 5

You have no idea.  Seriously, no idea how much this helped.  I had everything except that I had ng-show instead of ng-if.  I spent nearly 20 solid hours trying to get this to work, then i come across your post which makes absolute sense why it works.

Quick scenario:   So I had multiple sc_request records in a table.  I set up a separate <div> area that when the user clicked a ticket, the "widget-form" would get called via spUitl, and then show that ticket in my div area.  Don't get me wrong, even with ng-show it was all working, but the problem came when...

1. User loads page

2. User clicks request, it loads into <div> container (which contains the <sp-widget> element)

3. User clicks the attachment icon and uploads an attachment to the sc_request record, and it attaches just fine.

4. User now clicks into another request and that now loads into the <div> area

5. User tries to attach a file to this new record, but nothing happens! (or se we think)

6. What actually happens is that second attachment upload gets attached to that first viewed sc_request record!

7. No matter how many records we go to and try to attach, they all get attached to that first record.

 

The fix?  Change that ng-show to ng-if, thus destroying all that previous behind-the-curtain data of the previous record.

 

Brilliant!