The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to pass array from widget client script to server script after receiving broadcast

davilu
Mega Sage

Our team has a widget that broadcasts a number of data points and arrays stored in an object:

var obj = {
  catSelected: c.selected.cat_active,
  catName: c.selected.hro_category_name,
  catAppArr: c.selected.hro_category_apps,
  catDesc: c.selected.hro_category_desc,
  catSysID: c.selected.hro_category_sysID
}
$rootScope.$broadcast('changeCategories', obj);

On the other widget, we receive the broadcast:

$rootScope.$on('changeCategories', function(event, data) {
  c.server.get({
    action: 'retrieve_data'
  }).then(function() {
    c.data.appArr = data.catAppArr;
  });
})

and would like to send it over to the server side, how do we do this?  So far we have something like the below, but does not show up in the console:

if (input && input.action == 'retrieve_data') {
  data.test = input.appArr;
}

Do we even need c.server.get to pass that array over to the server?  Thanks for your help!

12 REPLIES 12

Community Alums
Not applicable

Sorry, I had to go and look at an example of how I've used this in the past.

Can you try using the data object in the response (r)

$rootScope.$on('changeCategories', function(event, data) {
  c.server.get({
    action: 'retrieve_data',
    appArr: ['someItem', 'anotherItem']
  }).then(function(r) {
    console.log("r.data.test: " + r.data.test)
    c.data.appArr = r.data.catAppArr;
  });
})

I really appreciate you taking the time to troubleshoot this with me!  I've changed client as such:

$rootScope.$on('changeCategories', function(event, data) {
  c.server.get({
	action: 'retrieve_data',
	appArr: data.catAppArr
  }).then(function(r) {
	console.log("r.data.test: " + r.data.test)
	c.data.appArr = r.data.catAppArr;
  });
})

In the console I see this:

find_real_file.png

and

Community Alums
Not applicable

What are you trying to do next?

We would like to use some of the data points in that array to do a GlideRecord query.

Community Alums
Not applicable

In that case, you can loop through each object in your array (r.data.test) and build your GlideRecord queries.