I want to pass server side data to client side on service portal.

saurabhchande
Tera Expert

Client side:

client side.PNG

Server side:

Server s ide.PNG

i am getting the values from array in html but I want to use it in client script.

I want to send the values which are in while loop of gliderecord and need to retrieve it in client script. Please help me in both - sending and retrieving. Many thanks.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

The common practice is to use the data object (noted in the comments) in your server script.



Example:



data.myNumber = 10;


data.myID = gs.getUserID();



Then in the client script,



var userID = c.data.myID;


View solution in original post

7 REPLIES 7

Thanks Chuck that helps.


Hi Chuck,

great post.  Another question...how can I get the data object to show in a popup modal?  I've got c.data.name defined in my client script, but if I put {{c.data.name}} into my modal script it's not recognized.  Thanks Chuck!

here's my popup modal script in the HTML of the widget:

<!--popup modal-->
<script>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Tech Hub</h4>
</div>
<div class="panel-body wrapper-xl">
Thank you, a ticket has been created on your behalf. You are number {{c.data.count}} in the queue. You will now be redirected to the home screen.
</div>
<div class="panel-footer text-right">
<button class="btn btn-primary" ng-click="c.closeModal()">${Close}</button>
</div>
</div>
</script>
<!--end popup modal-->

and here's the client script triggering the popup:

c.server.update().then(function(response){
var queueNumber = c.data.count;
var userName = c.data.name;
alert('userName is '+userName+' and queueNumber is '+queueNumber);

//popup modal
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope
});

//end popup modal

setTimeout(myFunction, 9000);
function myFunction(){
$window.location.href = 'https://dev54219.service-now.com/th_proto?id=techhub_index';
}
c.data = {};
$scope.c.affected_user.value = '';

}) }
}

YashikaG
Tera Contributor

Instead of declaring variable as var variable_name, declare it as data.variable_name, and use it as data.variable_name in client side and in HTML.