want to populate the logged in user on the " how can we help ? " message

tGhadage
Tera Contributor

Hi Guys, 

 

I want to populate the logged in username to " How can we help? " Message  below is my code please help with this. 

 

Html script : 

<div id="homepage-search" class="hidden-xs wrapper-xl">

 


<div class="wrapper-xl">


<h1 class="text-center text-4x m-b-lg sp-tagline-color">Hi {{data.user}}, Welcome to Portal.</h1>


<h4 ng-if="options.short_description" class="text-center m-b-lg sp-tagline-color" ng-bind="options.short_description"></h4>


<sp-widget widget="data.typeAheadSearch" />


</div>


</div> 

 

Client script :  

function() {
//Add greeting based on time of day and add user's first name
var c = this;
var today = new Date()
var curHr = today.getHours()
if (curHr < 12) {
c.data.greeting = 'Good morning ' + scope.user.first_name;
} else if (curHr < 18) {
c.data.greeting = 'Good afternoon ' + scope.user.first_name;
} else {
c.data.greeting = 'Good evening ' + scope.user.first_name;
}

 

Server script : 

 

(function() {
// Collect the User Info to Display Users First Name


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";


}


})();

attached a screenshot for your reference - 

 

Screenshot (186).png

it's not working with this code, I missed something. Please help!!

1 ACCEPTED SOLUTION

Hi @tGhadage ,

Please update your HTML code as below - 

HTML -

<div id="homepage-search" class="hidden-xs wrapper-xl">
<div class="wrapper-xl">
<h1 class="text-center text-4x m-b-lg sp-tagline-color">Hi {{c.data.greeting}}, Welcome to Portal.</h1>
<h4 ng-if="options.short_description" class="text-center m-b-lg sp-tagline-color" ng-bind="options.short_description"></h4>
<sp-widget widget="data.typeAheadSearch" />
</div>
</div> 

 

Please mark my answer as Helpful/Accept as Solution if it resolved your issue.

View solution in original post

6 REPLIES 6

Anirudh Pathak
Mega Sage

Hi @tGhadage ,

Please update your code as below - 

HTML:

 

<div id="homepage-search" class="hidden-xs wrapper-xl">
<div class="wrapper-xl">
<h1 class="text-center text-4x m-b-lg sp-tagline-color">Hi {{c.data.name}}, Welcome to Portal.</h1>
<h4 ng-if="options.short_description" class="text-center m-b-lg sp-tagline-color" ng-bind="options.short_description"></h4>
<sp-widget widget="data.typeAheadSearch" />
</div>
</div> 

 

Client -

 

api.controller = function() {
    /* widget controller */
    var c = this;
    var today = new Date();
    var curHr = today.getHours();
    if (curHr < 12) {
        c.data.greeting = 'Good morning ' + c.data.name;
    } else if (curHr < 18) {
        c.data.greeting = 'Good afternoon ' + c.data.name;
    } else {
        c.data.greeting = 'Good evening ' + c.data.name;
    }
};

 

Server - 

 

(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";
    }
})();

 

Hi @Anirudh Pathak , 

 

Thanks for your help its working fine ,

just for the greeting based on the time like good morning or good afternoon is not getting populated in the message. 

 

also need one help how can get search bar back in the home page below the message.

 

rest of it is working fine.

thanks!!

figured out the search bar part no issues its just the greeting message now.

Hi @tGhadage ,

Please update your HTML code as below - 

HTML -

<div id="homepage-search" class="hidden-xs wrapper-xl">
<div class="wrapper-xl">
<h1 class="text-center text-4x m-b-lg sp-tagline-color">Hi {{c.data.greeting}}, Welcome to Portal.</h1>
<h4 ng-if="options.short_description" class="text-center m-b-lg sp-tagline-color" ng-bind="options.short_description"></h4>
<sp-widget widget="data.typeAheadSearch" />
</div>
</div> 

 

Please mark my answer as Helpful/Accept as Solution if it resolved your issue.