Portal- Refreshing embedded widgets by option value

vzvinny
Kilo Explorer

In my Service Portal widget, I have an embedded widget that I am passing different record producer sys ID's into.

The approach I'm taking is using the client script to pass data to the server script as input.

The problem I'm seeing is that once the widget is loaded, I can't reload that widget using different option values.

HTML

          <sp-widget widget="c.data.recordProducerWidget"></sp-widget>

Client Script

$scope.showRPSoftware = function() {

  $scope.data.someID = "12345abcd";

  spUtil.update($scope);

  }

Server Script

data.recordProducerWidget=$sp.getWidget("sc-catalog-item", {sys_id: input.someID});

Any insight into how I can dynamically reload a widget from a client script would be great.

Thanks

7 REPLIES 7

HV1
Mega Guru

Try this:



HTML


<div class="elementRow" ng-if="c.data.recordProducerWidget">


          <sp-widget widget="c.data.recordProducerWidget"></sp-widget>


</div>



Client Script


$scope.showRPSoftware = function() {


  $scope.data.someID = "12345abcd";


  renderWidget('sc-catalog-item', {sys_id: $scope.data.someID});


}



function renderWidget(widgetID, params) {


  c.data.recordProducerWidget = null;


  spUtil.get(widgetID,params).then(function(response) {


  c.data.recordProducerWidget = response;


  });


  }



// REMOVE SERVER SCRIPT.


Server Script


//data.recordProducerWidget=$sp.getWidget("sc-catalog-item", {sys_id: input.someID});

I gave a thumbs-up because it seems like this is going in the right direction, but just as Serkan said, I keep getting "undefied".


For detailed info, see my post here: Re: Dynamically changing $sp.getWidget options in Client Script


Serkan Yilmaz
Tera Expert

Hi Vincent,



Do you get the given params from the "parent" widget in the embedded widget?



I created a new widget with an embedded widget. I'm trying to sent params from the new widget to the embedded widget.



1) Parent widget:


HTML:


<div class="embedded-widget">


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


</div>



Client controller:


spUtil.get("process-flow", {table:"change_request"}).then(function(response) {


                  c.processflow= response;


      });




2) Embedded widget:


Client controller:


console.log("Table: "+c.options.table);



Server script:


console.log("table: "+input.options.table +" - "+options.table);



All of these results for "console.log" are undefined.



Cheers,



Serkan