Widget - pass data to another widget to be used in server script

SC17
Tera Contributor

Hi.

I have 2 widgets. One has a GlideRecord script. I want to pass the result of this script to be used in another GlideRecord script in a different widget. I dont want to broadcast or emit the result to be used in HTML, I need to use the result in the server side.

Any ideas?

 

Thank you.

14 REPLIES 14

ChrisBurks
Mega Sage

One technique is to have a trigger to set parameters on the url with the value to pass.

Then in the other widget in the server side script capture those parameters with the give $sp.getParameter() method.

 

For example:

Widget A:

<div>
Widget A will place a parameter on the url.
</div>

Client Script (Controller):

api.controller=function($location,$timeout) { //inject $location and $timeout
  
  var c = this;
	
	 $timeout(function(){
			 $location.url("/sp?id=[id_of_your_page_here]&greet=world");
	 },3000)

};

 

Widget B

HTML:

<div>
  Widget B will replace the "myParam" property value when the parameter is appended in the URL.
  <h2>Hello {{ data.myParam }}</h2>
</div>

 

Server Script:

(function() {
  data.myParam = $sp.getParameter('greet') || '?';
})();

 

That is one of the basic ways of passing data from widget to widget or even page to page. ServiceNow uses this method often.

 

There are other ways too if this one doesn't work for you.

 

SC17
Tera Contributor

Thanks for the reply.

 

The issue is that I dont have the parameter on the URL.

 

I'm on a HR Task form, and I need to get the Parent Case so I can make a widget appear. I have this Parent Case sys in on one widget, need to pass it to the other so I can make some validations.

Do you have access to modify both widgets? If so, you would be making up your own parameters to meet your requirement.

Or if the second widget (widget that needs data at the server script) already accepts parameters then you would just be using the parameter it needs.

 

But to better help you can you provide more information about your setup?

For instance what is the trigger of when your data is supposed to be sent to the other widget? Is it when the GlideRecord script has the result? Are you able to modify both widgets?

Can you show a mock up of it or provide a walk-through of what the process flows?

 

-O-
Kilo Patron
Kilo Patron

The "first widget" that has the parent case unique value must be doing something to get to it. Worst case, can't you replicate the same in the "second widget"? Other than that (and the parameter solution) there is not way to reliably communicate between widgets server side.