Customise the "Homepage Search" widget to display first name

nathantenaglia
Tera Expert

Hi all,

Has anyone successfully updated the "Homepage Search" widget (or created their own) so rather than displaying the generic heading as per below:

Standard_Widget.jpg

It displays much the same way that the HI service portal homepage is configured by displaying a custom "Hi (first name of logged in user)". Example below.

Hi_Nathan.jpg

This would give our portal a more personal experience.

Cheers, Nathan.

1 ACCEPTED SOLUTION

diegosantiago
Kilo Expert

Server script:



(function() {


  /* populate the 'data' object */


  /* e.g., data.table = $sp.getValue('table'); */


     


      data.sysUserID = gs.getUserID();


              if (!data.sysUserID)


                                        data.sysUserID = gs.getUser().getID();


      var sysUserGR = new GlideRecord("sys_user");


      data.userExists = sysUserGR.get(data.sysUserID);



      if (data.userExists) {


              data.name = sysUserGR.getValue("first_name");


      } else {


              data.name = "User"


      }      



})();




HTML:



Edit this line and include the data.name element



<h1 class="text-center font-thin hidden-xs text-4x m-b-lg sp-tagline-color">{{options.title}} {{data.name}}?</h1>



In my case it show a message: "How can we help you, Diego?"


View solution in original post

9 REPLIES 9

diegosantiago
Kilo Expert

Server script:



(function() {


  /* populate the 'data' object */


  /* e.g., data.table = $sp.getValue('table'); */


     


      data.sysUserID = gs.getUserID();


              if (!data.sysUserID)


                                        data.sysUserID = gs.getUser().getID();


      var sysUserGR = new GlideRecord("sys_user");


      data.userExists = sysUserGR.get(data.sysUserID);



      if (data.userExists) {


              data.name = sysUserGR.getValue("first_name");


      } else {


              data.name = "User"


      }      



})();




HTML:



Edit this line and include the data.name element



<h1 class="text-center font-thin hidden-xs text-4x m-b-lg sp-tagline-color">{{options.title}} {{data.name}}?</h1>



In my case it show a message: "How can we help you, Diego?"


nathantenaglia
Tera Expert

Champion, that worked perfectly and has now been implemented within our test environment.



Thank you so much for taking the time to respond and help me out.



Cheers, Nathan.


VarunArulmani
Mega Expert

How can i locate the homepage widget's server script?


Varun:





Go to: http://your_instance.service-now.com/sp_config



choose the widget editor



select the homepage widget



If not checked, check the HTML and Server Script boxes