Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

[Help] Calling Logged In User First name to a Service Portal widget

Jordan14
Giga Expert

Hello All,

I'm creating a widget for my homepage where I'd like to say the users first name in the middle of the screen. For example " <firstname>, welcome to the Hub ".

Widget Code:

HTML:

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

  <div class="wrapper-md">

  <h1 class="text-center font-thin text-4x m-b-lg sp-tagline-color" ng-bind="options.title"></h1>

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

  </div>

</div>

CSS:

.sp-tagline-color {

color: $sp-tagline-color;

}

Cilent:

function() {   /* widget controller */   var c = this;}

Any idea I'd go about doing this?

All help appreciated.

Thanks,

Jordan

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

You should be able to get the user's first name from the scope, so write your client controller like this:



function($scope) {


var c = this;


c.welcome = $scope.user.first_name + " Welcome to the hub";


}



I am not sure where you wanted to put it in your html template, but you can reference it in there as {{c.welcome}}


View solution in original post

6 REPLIES 6

but where we can write this script?

scott barnard1
Kilo Sage

Just messing around you can try this



Widget for the banner



body html template



<section id="banner" style="background-color: {{data.bannerColor}}; background-image: url({{data.banner}});">


<div class="container">


      <div class="intro">


          <h1 class="title">${Hi} {{user.first_name}}</h1>


          <h4 class="message">{{options.welcome_message}}</h4>


      </div>


  </div>


</section>




Your banner and images to suit etc


then set up your welcome message etc