how to get data from client script to html.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 02:08 AM
This is HTML code,
<td class="ticket-symbol">✉️</td>
<td>Raised tickets</td>
<td class="circle-container">
<div class="circle">{{c.data.loggedInUser}}</div>
</td>
<td class="circle-container" id="raisedTicketCount">
<div class="circle" ng-bind="c.data.requestItemCount"></div>
</td>
This is Client side.
console.log("Client-side script is running...");
alert("Client-side script is running...");
c.server.get().then(function(response) {
console.log("Data fetched from server:", response.data);
c.data.loggedInUser = response.data.loggedInUser;
c.data.requestItemCount = response.data.requestItemCount;
});
This is server side script
(function() {
var userName = gs.getUser().getFullName();
data.loggedInUser = userName;
var requestItemCount = 0;
var requestItemGr = new GlideRecord('sc_req_item'); // Using 'sc_req_item' table for request items
// Add an encoded query to fetch items requested by the current logged-in user
requestItemGr.addEncodedQuery("requested_for.name=" + userName);
requestItemGr.query();
while (requestItemGr.next()) {
requestItemCount++;
}
// Send the data to the client-side script
data.requestItemCount = requestItemCount;
// Log for debugging
gs.info("Sending data to client: loggedInUser=" + data.loggedInUser + ", requestItemCount=" + data.requestItemCount);
gs.info("Request Item Count: " + requestItemCount);
gs.info("Current User's Username: " + userName);
})();
I want to display User full name and count of all tickets raised by logged in user. My logs are showing correct values but cannot fetch them in html and are not visible in the page. What am I doing wrong ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 02:22 AM
Hi @Hm10,
Are you building this in global or in a scoped app? In Global it is working fine for me.
In scoped I needed to change
var userName = gs.getUser().getFullName();
to
var userName = gs.getUser().getDisplayName();
Apart from that, please use a GlideAggregate Query instead of looping through the query result to get the amount of records.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 02:40 AM
Hi @Hm10 ,
If you have no operation to do in client script,then you can directly pass the data from server to HTML.
In HTML:
<div class="circle">{{data.loggedInUser}}</div>
<div class="circle">{{data.requestItemCount}}</div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 02:45 AM
Hello @Hm10
No need to use client script for this
you can directly access it via server side script in HTML like below
<td class="ticket-symbol">✉️</td>
<td>Raised tickets</td>
<td class="circle-container">
<div class="circle">{{data.loggedInUser}}</div>
</td>
<td class="circle-container" id="raisedTicketCount">
<div class="circle" ng-bind={{data.requestItemCount}}></div>
</td>
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 02:56 AM
This in not displaying for me