Service Portal :How to send data from calling widget to called widget.

Nithin12
Tera Expert

Hi All,

I have an Widget(Request) from where I am calling another widget (RITM Variables).

In RITM Widget server side code is written as:

server side code:

(function(){

  var gr = $sp.getRecord();

  data.canRead = gr.canRead();

  if (!data.canRead)

  return;

  data.tableLabel = gr.getLabel();

  data.variables = $sp.getVariablesArray();

  data.table = gr.getTableName();

  data.sys_id = gr.getUniqueValue();

})()

Client Controller

function ($scope, spUtil) {

  $scope.$on('record.updated', function(name, data) {

      spUtil.update($scope);

  })

}

Request Widget Server side code where I am passing values

if(input.getDetailsWidget && input.table && input.sys_id){

  data.details_widget = $sp.getWidget('widget-details', { table: input.table , sys_id : input.sys_id} );

  return;

  }

I am passing values (table and sys_id)trough input object from Request widget.

Here my issue is does $sp.getRecord() and $sp.getVariablesArray() will work when we are calling a widget from antoher widget as they take/consider current instance.Does they accept the value coming from input variable from calling widget(i.e table and sys_id).

I am getting following error:

find_real_file.png

Can any one guide/help me on this.

Developer Communitynathanfirthctomasi

Thanks,

Nithin.

1 ACCEPTED SOLUTION

When a widget is called using spUtil then the parameters passed are accessed using "input"


When a widget is called using $sp then the parameters passed are accessed using "options"



You can modify the code in the server side so it creates gr variable correctly - like so




  var gr;



  if(input && input.table && input.sys_id){


      gr = new GlideRecord(input.table);


      gr.get(input.sys_id);


  }


  else if(options.table && options.sys_id){


      gr = new GlideRecord(options.table);


      gr.get(options.sys_id);


  }


  else{


      gr = $sp.getRecord();


  }



  if(!gr || gr == null){


      return;


  }



View solution in original post

6 REPLIES 6

Hi Nithin,



Go for Try - catch to catch run time exceptions :



try {


// Your script for example:


  1.   var gr;  
  2.  
  3.   if(input && input.table && input.sys_id){  
  4.       gr = new GlideRecord(input.table);  
  5.       gr.get(input.sys_id);  
  6.   }  
  7.   else if(options.table && options.sys_id){  
  8.       gr = new GlideRecord(options.table);  
  9.       gr.get(options.sys_id);  
  10.   }  
  11.   else{  
  12.       gr = $sp.getRecord();  
  13.   }  
  14.  
  15.   if(!gr || gr == null){  
  16.       return;  
  17.   }  


}catch(error) {


// print error using "error"




}


The API was either designed by two different persons or by a single malicious person. In any case, not a good showcase of their work.