- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2024 11:55 PM - edited 06-02-2024 11:59 PM
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 -
it's not working with this code, I missed something. Please help!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 01:01 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 12:37 AM - edited 06-03-2024 12:42 AM
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";
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 12:52 AM - edited 06-03-2024 12:53 AM
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 01:01 AM
figured out the search bar part no issues its just the greeting message now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 01:01 AM
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.