Embedding widgets in Service Catalog

In Service Catalog you have the ability to embed a UI Macro as a variable in your catalog items or record producers. UI Macros are based on Jelly and as such they will not render in Service Portal. To work around this, you can now embed a widget for your UI Macro variables when displaying your catalog in Service Portal. In this example, we're going to create three variables, and make the third variable a widget that will display the sum of the other variables. Create a catalog item with the following variables: Single Line Text: "value1" Single Line Text: "value2" Macro: "results" On the "results" variable record, you will see a "Default Value" tab, with a reference to the Widget. Create and select a new widget called "Embedded Results", and use the following values: HTML: [crayon-5ceaac2c8430c279945479/] Client Script: [crayon-5ceaac2c84315348331320/] Now when you view this catalog item in the portal, the embedded widget will display the results of the two variables: Note, that the "field.change" event fires when the field loses focus, so you will have to tab or click out of the field to see the results.  

Using SCSS (SASS) Variables in Widgets

An issue I have come across in the past is keeping track of all the small CSS color changes etc. Fortunately, Service Portal supports the use of SCSS variables in the widget CSS. For example, instead of using CSS to define a color in every widget, set the dynamic Bootstrap variables in your Service Portal theme. You can also create your own custom variables to use in specific projects; i.e. $favorite-color. Here is an example of what it would look like in the Widget CSS: Now when a color needs to be changed across multiple widgets, you can change it in a single place. Service Portal also supports other SCSS features such as the use of Nesting, Mixins, and Operators. Note: The Service Portal SCSS implementation is a subset of the full SASS specification. To view a full list of default Bootstrap variables that you can customize, visit this link. If you would like to explore more, you can view the official ServiceNow documentation.

Using Custom Fonts In Service Portal

A question that I get asked a lot is how to use custom fonts in Service Portal. Here are the three primary ways: Option 1:  The easiest option is through Google Fonts. Select the Google font you want to use. Copy the font's style sheet URL. Go to your theme and add a new CSS Include. Make sure the "Source" is selected to URL and then paste the CSS URL. Click save. Now you can reference the font in your CSS. [crayon-5ceaac2c85889430085572/] Option 2: You'll need to encode your fonts using base64 and then include them in the CSS Includes of your theme. You can use this free tool by Font Squirrel: Create Your Own @font-face Kits | Font Squirrel. Use the "expert" option, then you will see an option for base64 encoding in the CSS section. Select "Base64 Encode." Once exported, add the generated code as a CSS include on your theme. For more information see: Learn how to create custom CSS in your theme here.   Option 3: Another approach is to upload your font files as attachments to the CSS Includes record and then reference them with "sys_attachment.do?" and passing in the sys_id as a parameter. See the following example:   For additional information on CSS fonts, here's an article that I have found to be very helpful. If you find this useful, let me know in the comments below.

Modal Windows in Service Portal

Modal windows in Service Portal are based on the BootstrapUI directives. For further documentation see: https://angular-ui.github.io/bootstrap/#/modal Below is a simple example of how to open up a modal window: Controller: [crayon-5ceaac2c865dc861162069/] HTML: [crayon-5ceaac2c865e3332322303/] Notes: Make sure the $uibModal service and $scope is included in the controller. In this example the modal template is just included in the HTML, but you could also set the "templateURL" property to an ng-template associated with this widget. You can manually pass in the scope to the template using the "scope" property.

Navigating Multiple Service Portals

A common question I get asked is how to link between two portals. Simply linking to the URL will not work due to Angular.js handling the routing. The easiest solution for this is to use target="_self" attribute on all hyperlinks: [crayon-5ceaac2c885dd965150163/] If you would like to redirect from within a widget client controller, you can use: $window.location.href:  HTML: [crayon-5ceaac2c885e4536084632/] Controller: [crayon-5ceaac2c885e8572596963/]  

AngularJS: Developing Modern User Interfaces

For those of you who did not attend K15, you missed out on a killer lab on AngularJS by Tyler Jones and Will Leingang. If you missed it and would like to check it out, it's now available through the community. Lab Overview: You have probably noticed that many new ServiceNow applications are built using AngularJS. In this lab, you'll create your own app and see how AngularJS and ServiceNow can work together to create incredible things.  Prerequisites: ServiceNow administration; Scripting in ServiceNow, Basic HTML, JavaScript and AngularJS. AngularJS_Lab_Guide.pdf 1.4 MB AngularJS_Slides.pdf 1.2 MB AngularJS_Update_Set.xml 9.8 K