how can I show a server side defined value in HTML in portal?

BhupeshK
Tera Contributor
 
2 ACCEPTED SOLUTIONS

amitshishod
Tera Guru

hello @BhupeshK 

You can use below code. it will work for you.

Server :
data.value = "Server Side Defined value";// Define a value using data object

HTML:
//Show it using ng-bind and {{}}

<p>Valuse Passed from Server Side to HTML: {{c.data.value}}</p>
<p ng-bind="c.data.value"></p>

Please mark my answer correct and helpful if it helps you.

View solution in original post

Juhi Poddar
Kilo Patron

Hello @BhupeshK 

To display a server-side value in an HTML template in Service Portal, you can use the following approach:

Server-Side Script (in the Widget's Server Script):

(function() {
    // Example: Fetching a user record
    var gr = new GlideRecord('sys_user');
    gr.get(gs.getUserID());
    data.userName = gr.getValue('name'); // Passing user name
    data.userEmail = gr.getValue('email'); // Passing user email
})();

 HTML Template (in the Widget's HTML Section):

<div>
    <p><strong>User Name:</strong> {{data.userName}}</p>
    <p><strong>User Email:</strong> {{data.userEmail}}</p>
</div>

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

5 REPLIES 5

BhupeshK
Tera Contributor

how can I show a server side defined value in HTML in portal?.Please help with script.

amitshishod
Tera Guru

hello @BhupeshK 

You can use below code. it will work for you.

Server :
data.value = "Server Side Defined value";// Define a value using data object

HTML:
//Show it using ng-bind and {{}}

<p>Valuse Passed from Server Side to HTML: {{c.data.value}}</p>
<p ng-bind="c.data.value"></p>

Please mark my answer correct and helpful if it helps you.

Ankur Bawiskar
Tera Patron
Tera Patron

@BhupeshK 

is this for widget?

If yes then this is how you can pass info from server side to HTML in widget

Server:

(function() {
data.name = gs.getUser().getDisplayName();
data.department = gs.getUser().getRecord().getDisplayValue("department");
})();

HTML:

<h4>Name: {{data.name}}</h4>

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

dgarad
Giga Sage

Hi @BhupeshK 

Server side :
data.value = "23";

HTML side:

<p>{{data.value}}</p>
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad