Skip to main content

Posts

Showing posts from February, 2021

Fix script bulk update bypassing workflow/engine/last updated fields

  ( function setProblemOnHold (){ var grProblem = new GlideRecord ( "problem" ); grProblem . addEncodedQuery ( "short_descriptionLIKEknown error" ); grProblem . query (); if ( grProblem . getRowCount () == 140 ){ grProblem . setWorkflow ( false ); grProblem . setUseEngines ( false ); grProblem . autoSysFields ( false ); grProblem . setValue ( "known_error" , true ); grProblem . updateMultiple (); } })();

Straight script include funtion, no class.create, initialise etc

 UI action condition: CanMoveToRCA() script include

Service Portal: change the page breadcrumb e.g. Knowledge Hub to something else

 look for the page that contains the name in the title:

ServiceNow: Service Portal - changing breadcrumbs

 https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0719179 format: // Breadcrumbs var bc = [{ label : 'My Stuff' , url : '?id=myStuff' }]; // This would be the pagename, myStuff is an example if ( $scope . data . tableLabel ) bc [ bc . length ] = { label : $scope . data . tableLabel , url : '#' }; bc [ bc . length ] = { label : $scope . data . number , url : '#' }; $rootScope . $broadcast ( 'sp.update.breadcrumbs' , bc ); }

Service portal: change to hover over icon using CSS / redirect to home page

in this particular case, an a href was causing problems / blowing up the image (it is embedded in a custom side menu)   HTML <img class = " homeicon " ng-click = "goToHome()" ng-src = "{{::portal.logo}}" title = "<a title>" role = "presentation" alt = "${Portal Logo}" /> client controller function ( $scope , $location ) { $scope . goToHome = function (){ $location . search ( "id" , "home" ); } } CSS img . homeicon : hover { cursor : pointer ; }

ServiceNow Service portal: pull in a background image using CSS

Service portal: pull in a background image using CSS  where the image is uploaded to images (db_image) table HTML: <div id="homepage-search" class="hidden-xs catalog-bg "  ng-init="c.trackPage()"> CSS: .catalog-bg {   background-image: url('/image123.png');   background-repeat: no-repeat;   background-position: right bottom; }

Service Portal: Redirect to home page (hidden behind company logo image)

normally this would happen by default out of the box as the image is located in the header menu   in this case the logo has been moved into a custom sidebar HTML: <img ng-click = "goToHome()" ng-src = "{{::portal.logo}}" title = "a title" role = "presentation" alt = "${Portal Logo}" /> client script: function ( $scope ) { var c = this ; $scope . goToHome = function (){ window . open ( "/ sp " , "_self" ); } } better way: function ( $scope, $location ) { var c = this ; $scope . goToHome = function (){ $location.search("id", "home"); } }

Service Portal: redirect from old portal to new portal

pull the following widget into your OLD portal home page to redirect to your NEW one: admin can override if they wish to, and toggled on/off via a sys property pulled in via the server script. HTML <div> REDIRECT TO NEW PORTAL </div> CLIENT CONTROLLER function ( $scope , $location ) { /* widget controller */ var c = this ; if ( c . data . redirect ) { var bProceed = false ; if ( c . data . isAdmin ) { bProceed = confirm ( 'redirect to new portal?' ); } else { bProceed = false ; } if ( bProceed ) { c . url = " /new_portal " ; $location . url ( c . url ); } } } SERVER SCRIPT ( function () { /* populate the 'data' object */ /* e.g., data.table = $sp.getValue('table'); */ data . redirect = false ; data . redirect = ( gs . getProperty ( 'portal.old.redirect' ) ==

ServiceNow - script include: build up the results as a JSON object (array) - example 2

function call var sCurrentGroupMembers = new <script_include> (). getGroupMembers ( group_sysid ); gs . print ( 'sCurrentGroupMembers:' + sCurrentGroupMembers ); var oGroupMembers = JSON . parse ( sCurrentGroupMembers ); gs . print ( JSON . stringify ( oGroupMembers . users )); oNewGroupMember = JSON . parse ( group_members ); var oGroupConfig = getGroupDeltas ( oGroupMembers . users , oNewGroupMember ); gs . print ( JSON . stringify ( oGroupConfig . remove )); gs . print ( JSON . stringify ( oGroupConfig . add )) output : *** Script: sCurrentGroupMembers: {"manager":"3b2649efdb0f8c10cc0652f3f39xxxxx", "email":"", "type":"33a2226edb99c340edfc7cbdae96xxxx", "description":"Created for xyz", "users":[{"user":"3b2649efdb0f8c10cc0652f3f396xxxx"},{"user":"856a8f71db3d73041b4ffc45ae96196a"},{"user":"3752771