ServicePortal display help desk phone number based on user location and/or parent company

Eli7
Tera Expert

Hi All,

 

I have a requirement to show a help desk phone number on the ServicePortal home page based on user location and for some users location and parent company.

 

At present there is a static phone number in the widget and based on logged in user I need to go to users company.location and return the phone number.

Can anyone share some code to achieve this?

Many Thanks!

2 REPLIES 2

mattystern
Kilo Sage

Hi @Eli7 

 

We do this for certain companies within our organization. I modified the "Homepage Greeting" widget (cloned the widget)

 

I modified the "server script" to include these lines for companies (I modified the comment and the number in this code) You should be able to get usr.location from this as well.

data.salutation_start = gs.getMessage('sp_homepage_salutation_start');
data.salutation_end = gs.getMessage('sp_homepage_salutation_end');

var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
data.first_name = usr.first_name.toString();
// if company is (comment each company name used), then show support number
if (usr.company == '82e47ffcdbd29b00e2ac34da7c961967' || usr.company == 'd32961eedb17f680a24fb96c4e961927' || usr.company == 'f51d72fb972cd154ba9a3b371153af36'||
 usr.company == '26ca593a87cc4190228bc99f8bbb3536' || usr.company == 'c0acee0d8730d110abc6bbff8bbb35d2' || usr.company == '55cad13a87cc4190228bc99f8bbb3598'||
 usr.company == 'fe0b597a87cc4190228bc99f8bbb35ae' || usr.company == '4d3ad5b687cc4190228bc99f8bbb3505'){ 
	data.support_number = "For 24/7 IT Support, Please call: 555-555-5555";
}

 

I then setup the HTML template like so to get the data.support_number:

<div id="homepage-search" class="padder-b-xl padder-t-md">
  <div class="wrapper-lg">
    <h1 class="text-center text-2x sp-tagline-color">{{data.salutation_start}}{{data.salutation_end}} {{data.first_name}}<br><br>{{data.support_number}}</h1>   
    <h1 class="text-center m-b-xl sp-tagline-color title" ng-bind="options.title"></h1>
    <h1 ng-if="options.short_description" class="text-center m-b-lg sp-tagline-color" ng-bind="options.short_description"></h1>
  </div>
</div>

 

I did write this awhile ago...I think I would probably add an else statement to set data.support_number to add something other than blank space. There's also not great scalability here - if new locations or companies are added, this script needs to be modified. Since we normalize our company records now, that's not a problem for me... If you find yourself constantly updating this, you may be able to utilize the user_criteria table.

 

-Matt

Hi Matt,

 

Thank you for the suggestion.

 

My requirement is a bit more complex. I need to get the user location and then phone number from the cmn_location entry  the user is mapped to. Any suggestions how to code this in the widget?

Thanks!