Category: Scenario-Based Questions PART 39
Updated on: August 12, 2025  |  0

Scenario-Based Questions PART 39

๐ŸŽ“ Scenario-Based Question

ย 

๐Ÿ‘‹ Custom Greeting & Task Display for Logged-in User on Portal

We want to greet the currently logged-in user by their first name and show the latest task they have opened. To achieve this:

1. Server-side Script

(function() {
  var usr = gs.getUserID();
  var userGR = new GlideRecord('sys_user');
  
  if (userGR.get(usr)) {
    data.fname = userGR.getValue('first_name');

    var taskGR = new GlideRecord('task');
    taskGR.addEncodedQuery('opened_by=' + userGR.getValue('sys_id'));
    taskGR.orderByDesc('sys_created_on');
    taskGR.query();

    if (taskGR.next()) {
      data.task = taskGR.getValue('number');
    }
  }
})();
  

2. Client-side HTML Template

<div>
  <h1>Hello {{data.fname}}</h1>
  <p>TASK opened by you ๐Ÿ‘‡</p>
  <p>{{data.task}}</p>
</div>
  

Steps to implement:
- Open your widget in the Widget Editor.
- Paste the server-side code into the Server Script section.
- Use the HTML template code in the HTML Template section.
- Save and test on your custom Service Portal.

๐ŸŽ‰ Now your portal visitors will see a friendly greeting along with the most recent task they opened!

Comments

No comments yet.


Log in to post a comment