Pass data from one widget to another widget

shiprashaw
Kilo Contributor

Hi All,

I need to pass data from field of one widget to another

How can i achieve this..

Kindly suggest

Thanks in advance..

1 ACCEPTED SOLUTION

chiragbagdai
Mega Expert

Hello Shipra,



User c.server.get() method in place of GlideAjax, as given in below example where you can pass query / variables in the object from client to server :


//user_details object contains all form field values + query_add variable



//Body HTML Template


<form ng-submit="submitForm(user_details)">


              <input type="text" ng-model="user_details.first_name" type="text" placeholder="First Name" class="form-control input-md" required="">    


              <button type="submit" ng-disabled="user_details.host_invalid == true" class="btn btn-md btn-primary pull-right">Submit</button>


</form>



// Client Controller


function ($scope) {


  /* widget controller */


  var c = this;


  $scope.submitForm = function (user_details) {


            user_details.query_add = "active=true";



            c.server.get({action : 'validate', user_details : user_details}).then(function(r) {


                      alert("Response from server "+r.data.result)


            });



  };


}



// Server script


(function() {


  if(input) {


       


            if(input.action == 'validate' && input.user_details.query_add == "active=true"){


                      // Script for validatation


                      data.result = true;


            }


              else {


                        data.result = false;


              }


  }


})();



Visit Widget scripting documentation provided by ServiceNow for more infor.



Regards,


Chirag


View solution in original post

4 REPLIES 4

ChrisBurks
Giga Sage

Hi Shipra,



This might be the answer you're looking for:


How to communicate between widgets in Service Portal


chiragbagdai
Mega Expert

Hello Shipra,



User c.server.get() method in place of GlideAjax, as given in below example where you can pass query / variables in the object from client to server :


//user_details object contains all form field values + query_add variable



//Body HTML Template


<form ng-submit="submitForm(user_details)">


              <input type="text" ng-model="user_details.first_name" type="text" placeholder="First Name" class="form-control input-md" required="">    


              <button type="submit" ng-disabled="user_details.host_invalid == true" class="btn btn-md btn-primary pull-right">Submit</button>


</form>



// Client Controller


function ($scope) {


  /* widget controller */


  var c = this;


  $scope.submitForm = function (user_details) {


            user_details.query_add = "active=true";



            c.server.get({action : 'validate', user_details : user_details}).then(function(r) {


                      alert("Response from server "+r.data.result)


            });



  };


}



// Server script


(function() {


  if(input) {


       


            if(input.action == 'validate' && input.user_details.query_add == "active=true"){


                      // Script for validatation


                      data.result = true;


            }


              else {


                        data.result = false;


              }


  }


})();



Visit Widget scripting documentation provided by ServiceNow for more infor.



Regards,


Chirag


ChrisBurks
Giga Sage

For future reference of those who may not know:


The title of this post is misleading as the correct answer marked here reflects not passing data from widget to widget but passing input data from client to server within the same widget.


Thanks Chris for your reply. By mistake, I have answered to this thread instead of send data from client to server in service portal.