Showing posts from February, 2018

Order Guides in Service Portal

tip: use cascade variables with variable names matching the catalog item variables rather than variable mappings from rule base entries, which doesn't seem to work too well in the portal

Order guide: make it service portal friendly

Catalog client scripts ensure that the UI type is set to 'all' or 'mobile / service portal', I have noted that on an order guide 'all' did not always work in the service portal but I got round this by creating 2 copies of the same script, one with UI type set to 'desktop' and the other to 'mobile / service portal'

Hide the delivery time on catalog items / order guide

workflow properties of the catalog item: schedule > set expected times to zero

ServiceNow Hide/show related list on form

locate the related list ID under 'system UI > related lists' then use script as below: show: function  onCondition ()   {         g_form . showRelatedList ( 'u_task_vendors.u_task' ); } hide: function  onCondition ()   {         g_form . hideRelatedList ( 'u_task_vendors.u_task' ); }

ServiceNow workflow: Wait for all approval blocks to approve before proceeding

Use a 'join' block in the workflow Example:

AJAX call example 1: return multiple values

AJAX call example 1: return multiple values Client script code: //--author: RDS Feb 2018 function  onChange ( control ,  oldValue ,  newValue ,  isLoading )   {      if   ( isLoading  ||  newValue  ==   '' )   {          // return;      }      //--default the line manager and job title from requested for field     g_form . setValue ( 'job_title' ,   '' );     g_form . setValue ( 'line_manager' ,   '' );      if   ( newValue != '' ){          var  ga  =   new  GlideAjax ( 'my_ajax_funcs_sc' );         ga . addParam ( 'sysparm_name' ,   'm_getuserinfo' );         ga . addParam ( 'sysparm_usersysid' ,  newValue );             ga . getXML ( function ( serverResponse ){                var  result  =  serverResponse . responseXML . getElementsByTagName ( "result" );                var  message  =  result [ 0 ]. getAttribute ( "message" );                //al

ServiceNow Access the active flag from a client side script

Display business rule: ( function executeRule ( current , previous /*null when async*/ ) {     // --RDS Feb2018 chg enhancements     //-- set scratchpad(s) which can then be used in client scripting/UI Policy scripts     g_scratchpad . chg_active = current . active ; })( current , previous ); Client script: alert ( g_scratchpad . chg_active ); //--seems to save scratchpad as a string, hence use: if ( g_scratchpad . chg_active == 'true' ){ }

ServiceNow: check if any values were modified on the form

example: check carried out in a 'risk assessment' client side UI action if( g_form.modified ){ alert('As values were changed, saving the form'); var; return; }

ServiceNow: see if any values on the form changed (client)

if (g_form.modified){              //---add code }

ServiceNow: save form in client script; gsftSubmit(gel('sysverb_update_and_stay'));

ServiceNow: check mandatory fields in client

For example if need to check from a client side ui action if the mandatory fields are complete var arrMand = g_form.getMissingFields(); if(arrMand.length>0){ alert('Complete mandatory fields'); }else{                 //--carry on }

ServiceNow: getting label title text

var el = gel("label.change_request.test_plan"); //var el = gel("status.change_request.test_plan"); alert(el.innerHTML); alert(el.title); alert(el.label-text);

ServiceNow: modifying field hint

options: use annotation via configure form layout > * annotations use g_form.showFieldMsg > use 4th boolean parameter and set to false to stop the form auto-scrolling to the field use g_form.addDecoration here's a rather clunky way of editing the change_request.test_plan hint: var el = gel("label.change_request.test_plan"); //var el = gel("status.change_request.test_plan"); alert (el.innerHTML); document.getElementById('status.change_request.test_plan').setAttribute('title', 'BLAHBLAH'); document.getElementById('status.change_request.test_plan').setAttribute('aria-label', 'BLAHBLAH'); alert(el.innerHTML);  var elements = el.getElementsByTagName('span'); alert('LEN: ' + elements.length); for(var i = 0; i < elements.length; i ++) {         if(elements[i].className === 'label-text') { alert('found!');             alert(elements[i]); elements[