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

Thanks Blaze. I wanted to edit the FAQ widget and this is what i see when i clicked edit.





find_real_file.png


You have to go into the widget editor, not the gear.


xiaix
Tera Guru

Interesting... the html code you provide didn't work for us, but this one did:


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


rightpalava
Mega Expert

Although the answer marked as correct does work, to display the user's name you can simply use {{user.first_name}} - no need to lookup, it's already available and ready to use.



<h1 class="text-center font-thin hidden-xs text-4x m-b-lg sp-tagline-color">Hi {{::user.first_name}}, {{options.title}}</h1>


Thanks. I was able to clone the homepage search widget and make the changes that was in the marked correct answer and then I added your h1 class html edit in place of the one they listed.



Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!