Skip to main content

Posts

Showing posts with the label scripting

ServiceNow Zurich: admins may not be able to edit script fields

    ServiceNow Zurich: admins may not be able to edit script fields New with ServiceNow Zurich: admins may not be able to edit script fields. A new role has been introduced and is required for anyone editing script fields:  snc_required_script_writer_permission https://www.servicenow.com/docs/bundle/zurich-platform-security/page/administer/security/concept/scripting-governance.html

ServiceNow add 24hrs to a date

ServiceNow add 1 day to a date  var gdt = new GlideDateTime (); gdt.addDaysLocalTime( 1 ); gs.info(gdt.getDisplayValue()); gs.info(gdt.getLocalDate()); ServiceNow add 24hrs to a date Date/Time: var gdt = new GlideDateTime (); //--for scoped app, use new GlideDateTime (; gs.info( 'GDT original milliseconds=' +gdt.getNumericValue()); gdt.add( 86400000 ); gs.info( 'GDT new milliseconds=' +gdt.getNumericValue()); gs.info( 'GDT=' +gdt); alternative var gdt = new GlideDateTime("2011-08-31 08:00:00"); var gtime1 = new GlideTime(); gtime1.setValue("00:00:20"); gdt.add(gtime1); var gtime2 = gdt.getTime(); var gdt = new GlideDateTime("2011-08-31 08:00:00"); gdt.addDaysLocalTime(-1); gs.info(gdt.getLocalDate()); Date: var gdt = new GlideDateTime (); gs.info( 'GDT original milliseconds=' +gdt.getNumericValue()); gdt.add( 86400000 ); gs.info( 'GDT new milliseconds=' +gdt.getNumericValue()); gs.info( 'GDT=' +gdt); v...

ServiceNow check that the date on a ticket is greater than today's date

 ServiceNow check that the date on a ticket is greater than today's date var iTodaysDate = gs.now(); var sTodaysDateTimeZero = new GlideDateTime (iTodaysDate.toString()); var iTodaysDateTimeZero = sTodaysDateTimeZero.getNumericValue(); var sACRdate = new GlideDateTime (requestGr.scheduled_start.toString()); var isACRdateTimeZero = sACRdate.getNumericValue(); var bFuture = (isACRdateTimeZero > iTodaysDateTimeZero);

ServiceNow Process an excel file attached to a fix script

 Process an excel file attached to a fix script main(); function main() { var excelDataJSON = this .getData(); if (excelDataJSON == null ) { gs.info( "No data in the excel file" ); return ; } this .processData(excelDataJSON); } function processData(excelDataJSON) { excelDataJSON.forEach( function (row) { var approle = row.application_role; var upn = row.upn } } function getDataFromAttachedExcelFile(grAttachmentSysId) { var myobjArray = []; var attachmentSID = grAttachmentSysId; // pass your excel attachment sys_id var parser = new sn_impex. GlideExcelParser (); var attachment = new GlideSysAttachment (); // use attachment sys id of an excel file var attachmentStream = attachment.getContentStream(attachmentSID); parser.parse(attachmentStream); while (parser.next()) { var row = parser.getRow(); var myData = ...

ServiceNow AJAX Client Script Include not working for user with no roles

 ServiceNow AJAX Client Script Include not working for user with no roles reproducible when impersonating that user solution: include this snippet in the client callable script include  isPublic: function() {         return true;     },   otherwise you may get a javascript error in browser console message and the AJAX function call will return null

ServiceNow Execute Flow Action from Script

 ServiceNow Execute Flow Action from Script    

ServiceNow Service Catalog Variables or Record Producer Variables in Client Script Using Scratchpad

 ServiceNow Service Catalog Variables or Record Producer Variables in Client Script Using Scratchpad see also:  https://docs.servicenow.com/bundle/vancouver-application-development/page/script/server-scripting/concept/c_ScriptableServiceCatalogVariables.html display business rule var varsArr = []; var variables = current . variables . getElements (); for ( var i = 0 ; i < variables . length ; i ++) { var question = variables [ i ]. getQuestion (); varsArr . push ( question . getName () + ":" + question . getLabel () + ":" + question . getValue ()); } g_scratchpad .rp variables = varsArr . toString (); //for multi row var varsMR = current . variables . getElements ( true ); var varsMR_Arr = []; for ( var i = 0 ; i < varsMR . length ; i ++) { var now_V = varsMR [ i ]; if ( now_V . isMultiRow ()) { var rows = now_V . getRows (); ...

ServiceNow RECORD PRODUCER / CATALOG ITEM VARIABLES in scripts - UPDATED VERSION

ServiceNow RECORD PRODUCER / CATALOG ITEM VARIABLES in scripts - UPDATED VERSION  see https://docs.servicenow.com/bundle/vancouver-application-development/page/script/server-scripting/concept/c_ScriptableServiceCatalogVariables.html Example to access variables of GlideRecord for the Task table var now_GR = new GlideRecord('sc_req_item'); if (now_GR.get('635a1f5387320300e0ef0cf888cb0b73')) { var variables = now_GR.variables.getElements(); for (var i=0;i<variables.length;i++) { var question = variables[i].getQuestion(); gs.log(question.getLabel() + ":" + question.getValue()) } } Example to access a multi-row variable set of GlideRecord for the Task table var now_GR = new GlideRecord('sc_req_item'); now_GR.get('02c38dcd87013300e0ef0cf888cb0bb2'); var vars = now_GR.variables.getElements(true); for (var i=0; i<vars.length; i++) { var now_V = vars[i]; if (now_V.isMultiRow()) { var rows = now_...

ServiceNow RECORD PRODUCER VARIABLES

ServiceNow RECORD PRODUCER VARIABLES  OPTION 1: var allVars = []; var sys_id = '14d3ca4b1b2ebd50af03dce0b24bcbfc' ; var producerVars_allVars = new GlideRecord ( 'question_answer' ); producerVars_allVars . addQuery ( 'table_sys_id' , sys_id ); producerVars_allVars . addQuery ( 'question.type' , '!=' , 11 ); producerVars_allVars . addQuery ( 'question.type' , '!=' , 19 ); producerVars_allVars . addQuery ( 'question.type' , '!=' , 20 ); producerVars_allVars . query (); while ( producerVars_allVars . next ()) { var varName = producerVars_allVars . question . name . toString (); if (! gs . nil ( varName )) { //if (varName == 'business_role_iga') { var sVar =( 'VARIABLE NAME: ' + producerVars_allVars . question . name . toString () + ' \nVARIABLE VALUE=' + ...

ServiceNow Workflows: Give a workflow a nudge from business rule

 ServiceNow Workflows: Give a workflow a nudge from business rule This is an example of how to "nudge" a workflow to ensure a wait for condition is re-evaluated (e.g. scripted wait for with a GlideRecord) as an alternative to broadcast event to workflow where you want to steer clear of events // Give the workflow a nudge to re-evaluate its Wait for condition var req = new GlideRecord ( 'task' ); if ( req . get ( current . parent )) { var wf = new global . Workflow (). getRunningFlows ( req ); while ( wf . next ()) { new global . Workflow (). broadcastEvent ( wf . sys_id , 'update' ); } }

ServiceNow Service Catalog Advanced Reference Qualifier in SCOPED app

ServiceNow Service Catalog Advanced Reference Qualifier in SCOPED app observations: the script include is created within the scoped app but needs to be accessible from all scopes client callable box does not need to be ticked example calling from the ref qual field on the catalog variable ( lookup select box ): javascript:'sys_idIN' + new x_cls_clear_skye_i.ClearSkyeTableServerSide().retrieveMemberships(current.variables.account) example calling from the ref qual field on the catalog variable ( list collector ): javascript:'sys_idIN'+new x_cls_clear_skye_i.ClearSkyeTableServerSide().retrieveMemberships(current.variables.account.toString()) note the 'variable attributes' field on the variable: ref_auto_completer=AJAXTableCompleter,ref_ac_columns=group (my observation is that ref_qual_elements =account causes the filter to BREAK!! So leave it out s. ee  https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0746780 also, it does not appear to b...