The CreatorCon Call for Content is officially open! Get started here.

Self service portal: Add language option on login page

lomouhamadou
Kilo Guru

Hi all,

Is it any simple way on the new Self service portal for adding the language option on the login page as we have on the backend?

thanks in advance

Regs,

Lô Mouhamadou

1 ACCEPTED SOLUTION

brett_karl
ServiceNow Employee
ServiceNow Employee

I completed a widget solution that ties into the Service Portal Header.



  1. Import the widget record that is attached to this reply
  2. Navigate to your header
  3. Find the following code in the Body HTML Template:

<ul ng-if="::user.logged_in" class="nav navbar-nav">


              <!-- chat, avatar, and logout -->


              <li ng-if="::data.connect_support_queue_id"><a href ng-click="openPopUp()">${Live Chat}</a></li>


         


              <li class="dropdown hidden-xs">


                  <a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown">


                      <span class="navbar-avatar"><sn-avatar class="avatar-small-medium" primary="userID" /></span>


                      <span class="visible-lg-inline">{{::user.name}}</span>


                  </a>



        Add the following code (to line 4):


<li><sp-widget widget="data.languagePicker"></sp-widget></li>



Navigate down to Server Script and add the following line.



  data.languageSelector = $sp.getWidget("language-picker", {});



The end result will look like this:


Screen Shot 2016-08-19 at 2.50.27 PM.png


Please let me know if you any more help!


View solution in original post

44 REPLIES 44

Yes, it has to do with the refresh time of the page. You need to add a timer, I will update the widget and send you the code in this thread in a little bit.



-Brett Karl


Hi Karl,



good idea again, it worked, thanks! (I put the $window.location.reload() into the timeout function:



function ($scope, $window, $timeout) {


  $scope.setLanguage = function(value) {


  $scope.data.newLanguage = value;


  $scope.server.update();


$timeout(function() {


      $window.location.reload();


  },500);


  };


};


Hi Brett,



Have you managed to get your language picker to change a user's language before login?


I have users logging in to a system without SSO and need various language options on the portal login page, and I've been having issues with using setPreference on non logged in users:


user.setPreference("user.language", input.newLanguage);


Does not appear to work


What I've actually found is that it seems the angular server update seems to fail for non-logged in users. So the input is never passed in to update preferences. If I hardcode a preference change, that works for a non-logged in user.


I'm getting the following errors in my console:


GET https://blah.service-now.com/angular.do?sysparm_type=get_user 401 (Unauthorized)


(anonymous) @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:11200


sendReq @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:11063


serverRequest @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:10988


processQueue @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:13849


(anonymous) @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:13864


$eval @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:14422


$digest @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:14329


$apply @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:14449


done @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:11104


completeRequest @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:11216


requestLoaded @ js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:11171


js_includes_sp.jsx?v=11-18-2016_1553&lp=Wed_Feb_01_08_49_42_PST_2017&c=10_51&lang=ga:11973 (authIntercepter) User has been logged out


I wonder if there is some other way to pass the info to the server?


Hi Brett,



You can't use setPreference in this case as the user is not logged in.


I managed to build the functionality so I will share later the script.