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

Nithin12
Tera Expert

I have tried by changing some code mentioned below now I am not seeing the the error message,But widget is getting called (I checked by console.log).




server side script


(function(){


  $sp.log('input tick widget'+input);//out put undefined


  $sp.log('input tick table'+input.table);//out put undefined


  $sp.log('input tick sys'+input.sys_id);//out put undefined


  var gr;


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


  gr = new GlideRecord(input.table);


  gr.get(input.sys_id);


  }


  //var gr= $sp.getRecord(input.table);


  data.canRead = gr.canRead();


  if (!data.canRead)


  return;



  data.tableLabel = gr.getLabel();


  data.variables = $sp.getVariablesArray(gr);


  data.table = gr.getTableName();


  data.sys_id = gr.getUniqueValue();


  $sp.log('gr '+gr);


  $sp.log('var'+$sp.getVariablesArray(gr));


  $sp.log('var sys'+$sp.getVariablesArray());


})()



Client Controller  


function ($scope, spUtil) {  


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


      spUtil.update($scope);  


  })    


}




Widget code(from where I am calling)



Server script


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


$sp.log('input widget'+input.getTicketDetailsWidget);//out put: true


$sp.log('input table'+input.table);//out put: sc_req_item


$sp.log('input sys'+input.sys_id); //out put: eC3hkajoojral******


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


  return;  


  }




Issue is Input is not getting populated in called widget(check first code logs mentioned in comments)for   which were set from calling widget(i.e.{ table: input.table , sys_id : input.sys_id}


any Idea?



Should I need to change Client Controller to populate input.



serviceportalpro ritesh can you guide me on this.


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;


  }



Thanks Ritesh for your response .


values are coming trough "options".



I am able to populate the data after doing some glide record into "data" object but at the end I am getting error.


Please refer the screen shot for error details.


find_real_file.png


Should I need to modify my client controller or any other thing which is stopping the execution.




Thanks,


Nithin.


Hi Nithin,



Did you get it resolved? As far as my understanding goes, you should use 'data.sys_id' and 'data.table' as parameters while calling the widgets. 'Data' is usually the server data. So, you should populate the data object with the table and sys_id and then pass this object to the called widget.Also,'input' is used to pass client data to server script.



Regards,


Darshak