I want to call a widget from another widget in Service Portal.

saurabhchande
Tera Expert

I want to call a widget from another widget in Service Portal. A parent widget is in the macro variable of a catalog item.. and there is a child widget containing few data.. I want to call the child widget in Parent widget and use the data in parent.

Childwidget will contain some server side script like :

var htmlname = "<some_text_here">;

data.htmlsysid = "<some_sysid>";

I want to send the data of child widget to parent widget and use it in parent widget.

Can anyone help here?

8 REPLIES 8

Hello Sachin,



I tried the same from the given link. But i couldn't send the data in another widget. No alert or console.log coming.


Liju John1
Mega Guru

down voteaccepted


On the Client Script, you can put your data to send to the Server Script in to c.data. Then on the Server Script, this is available in the input object.


Client Script


function () { var c = this;   c.myFunction = function () { // populate the c.data object c.data.cases= ['CASENUM01','CASENUM02','CASENUMO3'];   // send the c.data object to the server c.server.update().then(function () { // do cleanup if needed c.data.cases = []; }); } }

Server Script


(function() {   // input here contains c.data from client script if (input && input.cases) { for (var i = 0; i < input.cases.length; i++) { // write to system log gs.info(input.cases[i]); } } });

A good tutorial about this is at https://serviceportal.io/communicating-between-the-client-script-and-the-server-script-of-a-widget/


Tom Sienkiewicz
Mega Sage

I would not use $rootScope in the first widget to store the variables, only to broadcast the event.


Try something like: $scope.htmlvarname = c.data.htmlvarname


Also I am assuming you want to pass the actual data in the event, not a string? get rid of the second ' '



Second widget seems to be OK, I guess you can use both $rootScope.$on and $scope.$on, I always do the latter.


Now the data is coming into my another widget with the help of timeout function. But because of timeout the data is coming in delay, hence I am not able to send it to server side because it is loaded first. Any way to send the data after the timeout function is loaded ?