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

You need to pass the appArr within the input object:

 

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

 

Thanks @Dustin Watkins !  I gave that a shot, but data.test still doesn't show up in the console.  Any other suggestions?  Thanks again.

Community Alums
Not applicable

Where are you logging it to the console?  Can you try it here?

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

it shows "data.test: undefined".  Is the below server script portion correct?

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