How to get values ​​from fields in a portal form widget and pass them to other widgets

bonsai
Mega Sage

I would like to read field values ​​from a portal form widget and pass them to another widget.

I would also like to receive values ​​from other widgets and set them in fields.

Is this possible?

 

bonsai_0-1756787974729.png

 

1 ACCEPTED SOLUTION

kaushal_snow
Mega Sage

Hi @bonsai ,

 

Yes Possible...Use $broadcast, $emit, and $on - most widely used pattern

In the source widget (sender):

// In the client controller
$rootScope.$broadcast('myEventName', valueToShare);


In the target widget (receiver):

// In the client controller
$scope.$on('myEventName', function(event, receivedValue) {
$scope.myReceivedValue = receivedValue;
});


This lets you send a value from one widget (e.g. a form input) and have another widget capture and use it...


Alternate approach: If you need to pass data that the server script of another widget uses..

 

In Widget A, push parameters into the URL using $location:

api.controller = function($location, $timeout) {
$timeout(function () {
$location.url("/sp?id=somePage&sharedValue=" + encodeURIComponent(value));
}, 100);
};


In Widget B server side script, capture it:

(function() {
data.value = $sp.getParameter('sharedValue');
})();


Detailed article here: https://www.servicenow.com/community/developer-forum/service-portal-need-to-pass-the-value-from-one-...

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@bonsai 

what's your actual business requirement here?

You can always communicate between 2 widgets by passing info

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Bhimashankar H
Mega Sage

Hi @bonsai ,

 

Yes it is possible to share field values between Service Portal widgets, including reading values from a form widget and passing them to another widget.

 

For inter-widget communication:

  • Widgets can broadcast and listen for events via $rootScope.

  • You can use $broadcast method of information to be communicated/shared.
  • In Second widget receiving the values using $on method.

 

This post explained in detail.

Get a variable Value and present it to another page in another widget. 

 

Article:

How to comunicate between widgets - Service Portal 

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

kaushal_snow
Mega Sage

Hi @bonsai ,

 

Yes Possible...Use $broadcast, $emit, and $on - most widely used pattern

In the source widget (sender):

// In the client controller
$rootScope.$broadcast('myEventName', valueToShare);


In the target widget (receiver):

// In the client controller
$scope.$on('myEventName', function(event, receivedValue) {
$scope.myReceivedValue = receivedValue;
});


This lets you send a value from one widget (e.g. a form input) and have another widget capture and use it...


Alternate approach: If you need to pass data that the server script of another widget uses..

 

In Widget A, push parameters into the URL using $location:

api.controller = function($location, $timeout) {
$timeout(function () {
$location.url("/sp?id=somePage&sharedValue=" + encodeURIComponent(value));
}, 100);
};


In Widget B server side script, capture it:

(function() {
data.value = $sp.getParameter('sharedValue');
})();


Detailed article here: https://www.servicenow.com/community/developer-forum/service-portal-need-to-pass-the-value-from-one-...

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Bhimashankar H
Mega Sage

Hi @bonsai ,

 

I hope you saw my reply. 


If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. It will help future readers as well having similar kind of questions and close the thread.

Thanks,
Bhimashankar H