Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Can not get the sent Options of the embedded widget

Serkan Yilmaz
Tera Expert

Hi,

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

12 REPLIES 12

Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Serkan



Not the best solution but you can try to do something like this.



  spUtil.get("process-flow").then(function(response) {


                  c.options.sys_id = "test sys id";


                  c.processflow= response;


      });



I didn't find anything better and at least works with the cool clock widget where you can set at least 3 options params



Cheers


R0bo


If the data that is needed can be accessed via the html markup then the best and easiest thing I think would be to use the widget directive:



<div ng-repeat="item in c.some_items">


        <widget id="[widget id here]"   options="item"></widget>


</div>



Note: this widget does the same thing as the <sp-widget></sp-widget> directive except it doesn't require making a variable in the controller and it's not prepended with "sp-". Just use the widget id of the desired widget.


Suri2
ServiceNow Employee
ServiceNow Employee

I had the same issue. I was unable to send values to embedded widget from parent's client controller. So, I used the options in html directly. Here is my working example:

Parent Widget:

HTML:

<div>
<widget id='embedded-widget' options='{"name" : "smc"}'> </widget>
</div>

Nothing in client controller and server script

Embedded Widget:

HTML:

<div>
<div> {{name}} </div>
</div>

Client Controller:

function($scope) {
var c = this;
$scope.name = c.options.name;
}